ASP file download button

AgentZap

Senior member
Sep 1, 2001
730
0
0
So I have a download button on my C# asp form. Essentially it uses

Response.Redirect (fileNameHere);

to download the file. The problem with this method is that it tries to display the file in the browser. I would rather it give the user a Save As dialogue. What method should I call instead?
 

kamper

Diamond Member
Mar 18, 2003
5,513
0
0
I believe that's totally up to the browser, and it makes its decision based on the mime type your server reports. If it knows how to view it, it will try.

What you'd want to do is somehow configure iis to report a different mime-type for those files. Maybe you can just do it for files in a certain location, maybe you have to change it for every file of a certain extension for the whole server. A way that takes a little more work but is more controllable is, instead of redirecting the response, set the mime-type by hand, open the file and stream it out of the response. I suspect that could lead to some sluggish performance if you are under particularly heavy load though.
 

AgentZap

Senior member
Sep 1, 2001
730
0
0
My professor mentioned there may be some kind of "javascript" solution for this. Anyone run across anything like that?
 

beggerking

Golden Member
Jan 15, 2006
1,703
0
0
use webbrowser control..

Friend WithEvents web1 as AxSHDocVw.AxWebBrowser
in click event
web1.ExecWB(SHDocVw.OLECMDID.OLECMDID_SAVEAS)