Send a suggestion!

We're building a brand new version of the site, and we'd love to hear your ideas

Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

Rated
Read 86,951 times

Related Categories

Force 'file download' for known file types

Multipurpose Internet Mail Extensions (MIME) is a wonderful thing,
allowing your Web browser to automatically display content of many
different formats natively within the browser window. However,
sometimes, you may want users to download this content to their
client computer rather than simply viewing it in the browser. But
how do you override the browser's determination to render known
MIME types itself? The answer is to use a content disposition
header in your Web page.

Suppose you've written an ASP page that contains a link to a known
MIME type, but you want the user to download the file instead of
viewing it. Add the following to your script:

response.addHeader "content-disposition", "attachment;
filename=filename.ext"

Then substitute the actual filename and extension, and it's as good
as done. When your users click on the link, they'll immediately see
the download dialog box instead of the file's contents.

© 2001 Element K Journals, a division of Element K Press LLC ("Element K"). Element K and the Element K logo are trademarks of Element K LLC

Comments

  • Posted by OthelloNYC on 31 May 2005

    Does this also work to write a file from memory data to a client machine?

  • not working in netscape

    Posted by a_praveen_reddy on 17 May 2005

    Will the same code work in netscape/mozilla

  • File Download Box

    Posted by NimaNima on 01 Dec 2004

    Hi,

    I am simply trying to create the File Download Box when a user clicks on file links. Can you help? Is the code you listed all that is neeeded? I have tried to search for a reliable way on the ...

  • downloading an xml file using c#

    Posted by umarani on 02 Aug 2004

    I want to open an xml file in asp.net.
    I have used the following lines in my code :
    Response.ContentType = "application/vnd.ms-xml";
    Response.AddHeader("Content-Disposition", "attachment; filename=...

  • FORCE 'FILE DOWNLOAD' WITH HTML PAGE

    Posted by heman on 14 Jun 2004

    I am trying to force a download to a HTA page in a HTML page, but how do I do this, that script given in a later posting doesn't work, which I figured since I am not creating an .asp page?