C# 将字符串导出到CSV不起作用

C# 将字符串导出到CSV不起作用,c#,csv,export-to-csv,C#,Csv,Export To Csv,我正在尝试使用以下代码将字符串下载到CSV文件中: string attachment = "attachment; filename=Test.csv"; HttpContext.Current.Response.Clear(); HttpContext.Current.Response.ClearHeaders(); HttpContext.Current.Response.ClearContent(); HttpContext.Current.Response.AddHeader("con

我正在尝试使用以下代码将字符串下载到CSV文件中:

string attachment = "attachment; filename=Test.csv";
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ClearHeaders();
HttpContext.Current.Response.ClearContent();
HttpContext.Current.Response.AddHeader("content-disposition", attachment);
HttpContext.Current.Response.ContentType = "text/csv";
HttpContext.Current.Response.AddHeader("Pragma", "public");
HttpContext.Current.Response.Write("my,csv,file,contents");
HttpContext.Current.Response.End();
我的小提琴手捕捉到了以下信息:

 HTTP/1.1 200 OK
 Server: ASP.NET Development Server/10.0.0.0
 Date: Wed, 18 Sep 2013 22:06:19 GMT
 X-AspNet-Version: 4.0.30319
 content-disposition: attachment; filename=Test.csv
 Pragma: public
 Cache-Control: private
 Content-Type: text/csv; charset=utf-8
 Content-Length: 20
 Connection: Close

 my,csv,file,contents
但是,浏览器没有下载任何CSV文件。 请帮忙。
谢谢,

标题应写为
内容处置
-注意名称中的大写字母。有关详细信息,请在中搜索
19.5.1内容处置

例如:

Content-Disposition: attachment; filename="fname.ext"
还要注意文件名周围的双引号


该问题是一个异常:Sys.WebForms.PageRequestManagerParserErrorException:无法解析从服务器收到的消息

找到一篇有用的文章

找到了解决办法


谢谢,

问题不是这个。我已经找到了答案并发布了。谢谢你的回复。