using response object to cause save prompt (Content-Disposition Attachment Header Does Not Save File)


I am using url rewriting to stop file downloads from my site for files that have pdf or txt extensions in the url eg.
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:

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.
LVL 12
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

set the content-type property to octetstream.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
deanvanrooyenAuthor Commented:
i have returned to solving this, i will let you know how it goes - do you use the server transfer or response.write, can you give me an example.
deanvanrooyenAuthor Commented:
hi the points are yours anyways ,

I found a good way to do it:

        string ContentType = "application/octet-stream";
        Response.AddHeader("Content-Disposition", "attachment; filename=\"FILENAME\"");
        Response.Charset = "UTF-8";
        Response.ContentType = ContentType;

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.