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

Posted on 2006-04-19
Last Modified: 2008-03-06

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.
Question by:deanvanrooyen
    LVL 23

    Accepted Solution

    set the content-type property to octetstream.
    LVL 12

    Author Comment

    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.
    LVL 12

    Author Comment

    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;


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now