How to prevent ASP.NET from changing the file extension on SaveAs-Box?

  • Thread starter Thread starter Winston
  • Start date Start date
W

Winston

Hi Group,
in my aspx page there is an Response.Redirect to a file called myfile.csv.
The file consists of plain text with comma separated values.
I want that the browser opens the save as dialog which it does.
So far so good.

But the filename, the Internet Explorer suggests is not myfile.csv but myfile.xls.
Why does the IE change the file extension?

How can I have the save as dialog with the correct suggestion of the filename?

Any help appreciated,
Winston
 
Winston,
You can probably try to alter the MIME types on the server, but if
you're redirecting to a csv there probably isn't much. IE is probably
identifying the csv with Excel since it is a commonly used file to import
data into Excel or out of it. You can try something like identifying a MIME
type of csv to application/octet-stream so that IE will hopefully be forced
to download it.


Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage
 
Some code like this should do the trick.
Response.AddHeader("Content-Disposition","attachment;filename=myfile.csv");
 
Steve C. Orr said:
Some code like this should do the trick.
Response.AddHeader("Content-Disposition","attachment;filename=myfile.csv");


Hi Steve,
unfortunately not. I tried it and the IE still changes the file
extension from .csv to .xls. Any ideas?

Winston
 
Excel is the default application associated with CSV files.
But it seems you don't want your CSV files associated with Excel?
Can you use another extension besides CSV?

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net



Winston said:
"Steve C. Orr [MVP, MCSD]" <[email protected]> wrote in message
Some code like this should do the trick.
Response.AddHeader("Content-Disposition","attachment;filename=myfile.csv");


Hi Steve,
unfortunately not. I tried it and the IE still changes the file
extension from .csv to .xls. Any ideas?

Winston


 
Back
Top