I have a web application using aspx and with C# code. I am using HttpResponse
to be able to download the result in a CSV file.
When I use Chrome it downloads without problems with the .csv extension. The problem is when I use FireFox, the file it downloads is file (no extension).
Here is my part of code usingHttpResponse
System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
response.ContentType = "text/csv";
response.AddHeader("Content-Disposition", "attachment; filename=" + outCsvFile + ";");
response.TransmitFile(outCsvFile);
response.Flush();
response.End();
What could be the problem?
Make sure the file name has the required extension. That is, the name you indicate in the header
"filename="
must have the extension.csv
in it.Example:
Perhaps Chrome is kind enough to add that extension after validating the content-type of type "text/csv".
I had the same problem to download a .PDF in Firefox
. I leave this example code, maybe it can help someone else. They can use the backslash "\" at the beginning and end of the file name.