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

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
 
M

Mark Fitzpatrick

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
 
S

Steve C. Orr [MVP, MCSD]

Some code like this should do the trick.
Response.AddHeader("Content-Disposition","attachment;filename=myfile.csv");
 
W

Winston

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
 
S

Steve C. Orr [MVP, MCSD]

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


 
E

Eric Lawrence [MSFT]

Is there a public URL that you've got this code running on? I'd like to
look at the Headers.

--
Thanks,

Eric Lawrence
Program Manager
Assistance and Worldwide Services

This posting is provided "AS IS" with no warranties, and confers no rights.

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


 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top