CSV boots as HTM

I have a huge problem in all browsers.

I have a website where clients can upload a csv file containing the details they need.

The problem I encountered is that the csv file is either downloaded without the extension, or as an htm file.

In the code I specify the file name with .csv, the file on the server is also .csv.

The code is as follows

context.Response.Buffer = true;
context.Response.Clear();
context.Response.ClearHeaders();                    
context.Response.ContentType = "text/csv";
context.Response.AppendHeader("Content-Disposition", @"attachment,     
     filename=" + ((string)Path.GetFileName(downloadFilePath)));
context.Response.WriteFile(downloadFilePath);
context.Response.Flush();
context.Response.Close();

I tried context.Response.ContentType = "text/html";and context.Response.ContentType = "application/octet-stream";.

Powered by IIS6.

Does anyone know what could be causing this?

+5
source share
2 answers

Well, I developed why the files do not load as CSV.

because there are spaces in the file name, so I need to enclose the file name so that it does not interrupt in space.

thank you for your help

0

, , , Content-Disposition ;? , , .

:

context.Response.AppendHeader(
    "Content-Disposition",
    string.Format(
        "attachment; filename=\"{0}\"",
        Path.GetFileName(downloadFilePath)));
+2

All Articles