[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2006-04-19
3
Medium Priority
?
233 Views
Last Modified: 2008-03-06
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
0
Comment
Question by:deanvanrooyen
  • 2
3 Comments
 
LVL 23

Accepted Solution

by:
naveenkohli earned 750 total points
ID: 16492128
set the content-type property to octetstream.
0
 
LVL 12

Author Comment

by:deanvanrooyen
ID: 16618981
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.
thanks
0
 
LVL 12

Author Comment

by:deanvanrooyen
ID: 16642037
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;

        Response.WriteFile("../uploads/FILENAME.EXT");
        Response.End();
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Loops Section Overview
Suggested Courses
Course of the Month18 days, 8 hours left to enroll

825 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