Downloading .CSV file in firefox does not work correctly with web application

3

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 extension .csv. The problem is when I use FireFox, the file that downloads is file (without extension).

Here is my part of code using HttpResponse

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?

    
asked by A arancibia 10.02.2016 в 20:15
source

2 answers

6

Make sure that the name of the file has the required extension. That is, the name you indicate in the header "filename=" must have the extension .csv in it.

Example:

string nombre = outCsvFile + ".csv";
response.AddHeader("Content-Disposition", "attachment; filename=" + nombre + ";");

Maybe Chrome is kind and is adding that extension after validating the content-type of type "text / csv".

    
answered by 10.02.2016 / 20:20
source
0

I had the same problem to download a .PDF in Firefox
I leave this example code, maybe I can help someone else. You can use the backslash "\" at the beginning and end of the file name.

Ressponse.Clear();
Response.AppendHeader("content-disposition", "attachment; filename=" + "\"" + FileName + "\"");  
Response.ContentType = "Application/pdf";
Response.WriteFile("~/Logs/temp/" + FileName);
    
answered by 09.08.2018 в 20:20