I am trying to download a string into CSV file with the following code:
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();
My Fiddler capture gave me the following:
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
But, the browser is not downloading any CSV file. Please help. Thanks,