I am having a huge problem in all browsers.
I have a site where clients can download a csv file that contains detail they need.
The problem I am having is that the csv file either downloads with no extension or as a htm file.
In the code I am specifying the file name with .csv, the file on the server is also a .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 have tried context.Response.ContentType = "text/html";
and context.Response.ContentType = "application/octet-stream";
.
It is running on IIS6.
Does anybody know what could be causing this?
Assuming your verbatim string literal is on a single-line in your source, have you tried replacing the ,
in your Content-Disposition
header with a ;
? Examples I have found always use a semi-colon there.
It also might be safer to use quotes around your filename to protect the header from special characters:
context.Response.AppendHeader(
"Content-Disposition",
string.Format(
"attachment; filename=\"{0}\"",
Path.GetFileName(downloadFilePath)));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With