C#导出到txt文件的三种方法
2012-03-12 17:25
190 查看
方法一:
HttpResponse resp = System.Web.HttpContext.Current.Response;
resp.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
resp.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlPathEncode(FileName));
resp.Write(sb.ToString());
方法二:
Console.WriteLine(sb.ToString());
FileStream aFile = new FileStream("D:\\temp\\lintest.dat", FileMode.OpenOrCreate);
StreamWriter sw = new StreamWriter(aFile);
sw.Write(sb.ToString());
sw.Close();
方法三:
Response.Clear();
Response.Buffer = true;
Response.ContentType = "text/richtext";
Response.AddHeader("content-disposition", "attachment; filename=" + HttpUtility.UrlEncode(FileName, Encoding.UTF8) + ";size=0");
Response.Write(sb.ToString());
Response.Flush();
Response.End();
HttpResponse resp = System.Web.HttpContext.Current.Response;
resp.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
resp.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlPathEncode(FileName));
resp.Write(sb.ToString());
方法二:
Console.WriteLine(sb.ToString());
FileStream aFile = new FileStream("D:\\temp\\lintest.dat", FileMode.OpenOrCreate);
StreamWriter sw = new StreamWriter(aFile);
sw.Write(sb.ToString());
sw.Close();
方法三:
Response.Clear();
Response.Buffer = true;
Response.ContentType = "text/richtext";
Response.AddHeader("content-disposition", "attachment; filename=" + HttpUtility.UrlEncode(FileName, Encoding.UTF8) + ";size=0");
Response.Write(sb.ToString());
Response.Flush();
Response.End();
相关文章推荐
- C# 导出txt的三种方法
- C#导出数据到CSV和EXCEL文件,过长的数值被转义的解决方法
- C#读写txt文件的两种方法介绍 Copy:http://blog.csdn.net/ybhjx/article/details/53706715
- C# 读取EXCEL文件的三种经典方法
- C#导出数据到CSV和EXCEL文件时,过长的数值被转义的解决方法
- 导出大批量图片的名字到txt文件的一种笨但有效的方法
- 黑马程序员之C#学习笔记:C#读取txt文件的方法
- C#导出数据到EXCEL文件,过长的数值被转义的解决方法
- C# 读取EXCEL文件的三种经典方法
- C#导出数据到CSV和EXCEL文件,过长的数值被转义的解决方法(3)
- C#读写txt文件的两种方法介绍
- C# 读取EXCEL文件的三种经典方法
- C#读写txt文件的两种方法介绍
- C#将文本框中的字符串导出至txt文件中
- C#_读取EXCEL文件的三种经典方法
- Java导出txt文件的方法
- Datagrid数据导出到excel文件的三种方法
- C#读写txt文件的两种方法介绍
- C#读写txt文件的两种方法介绍
- C#创建Excel(.xls和.xlsx)文件的三种方法