数据导出到TXT文件

来源:互联网 发布:企业邮箱搜索软件 编辑:程序博客网 时间:2024/05/17 01:10
        public static void WriteTXTFile(List<string> ExportList, string FilePath, string FileName)        {            #region Check Folder File path            if (!Directory.Exists(FilePath))            {                try                {                   Directory.CreateDirectory(FilePath);                 }                catch (Exception ex)                {                    throw new Exception("can not create this filepath!");                }            }            if (FilePath.EndsWith(@"\"))                FilePath = FilePath + FileName;            else                FilePath = FilePath + @"\" + FileName;            if (File.Exists(FilePath))            {                File.Delete(FilePath);            }            #endregion            using (StreamWriter sw =            new StreamWriter(new FileStream(FilePath, FileMode.CreateNew), Encoding.UTF8))            {                for (int i = 0; i < ExportList.Count; i++)                    sw.WriteLine(ExportList[i]);            }        }


原创粉丝点击