deanvanrooyen
asked on
using response object to cause save prompt (Content-Disposition Attachment Header Does Not Save File)
Hi,
I am using url rewriting to stop file downloads from my site for files that have pdf or txt extensions in the url eg. www.mysite.com/rep1.pdf.
What I am doing is using a datalist with the pdf/txt files listed on a web form and then a button next to the file where the user can click it and get the file. In the handler for the onitemcommand event I am getting the filename and using Server.Transfer to transfer to url of say the pdf/txt file and it opens the pdf fine in a browser window. The txt file just opens in the broswer as html - what I need is it to prompt to down load the file. I have tried a few things eg. using respnse.write and changing the html header Content-Disposition to Attachment but this does not work.
this issue is on the ms kb:
http://support.microsoft.com/default.aspx/kb/279667
I cannot work out how to resolve this - my txt file actually has a different extension on the server (.acz)... I would like to use the response. write method and force a file download in any sort of way.
thanks
I am using url rewriting to stop file downloads from my site for files that have pdf or txt extensions in the url eg. www.mysite.com/rep1.pdf.
What I am doing is using a datalist with the pdf/txt files listed on a web form and then a button next to the file where the user can click it and get the file. In the handler for the onitemcommand event I am getting the filename and using Server.Transfer to transfer to url of say the pdf/txt file and it opens the pdf fine in a browser window. The txt file just opens in the broswer as html - what I need is it to prompt to down load the file. I have tried a few things eg. using respnse.write and changing the html header Content-Disposition to Attachment but this does not work.
this issue is on the ms kb:
http://support.microsoft.com/default.aspx/kb/279667
I cannot work out how to resolve this - my txt file actually has a different extension on the server (.acz)... I would like to use the response. write method and force a file download in any sort of way.
thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
hi the points are yours anyways ,
I found a good way to do it:
string ContentType = "application/octet-stream" ;
Response.AddHeader("Conten t-Disposit ion", "attachment; filename=\"FILENAME\"");
Response.Charset = "UTF-8";
Response.ContentType = ContentType;
Response.WriteFile("../upl oads/FILEN AME.EXT");
Response.End();
I found a good way to do it:
string ContentType = "application/octet-stream"
Response.AddHeader("Conten
Response.Charset = "UTF-8";
Response.ContentType = ContentType;
Response.WriteFile("../upl
Response.End();
ASKER
thanks