How To Raise a "File Download" Dialog Box for a Known MIME Type

Article translations Article translations
Article ID: 260519 - View products that this article applies to.
This article was previously published under Q260519
Expand all | Collapse all

SUMMARY

When you serve a document from a Web server, you might want to immediately prompt the user to save the file directly to the user's disk, without opening it in the browser. However, for known MIME (Multipurpose Internet Mail Extensions) types such as Microsoft Word ("application/ms-word"), the default behavior is to open the document in Internet Explorer.

You can use the content-disposition header to override this default behavior. Its format is:
Content-disposition: attachment; filename=fname.ext
				

MORE INFORMATION

Content-disposition is an extension to the MIME protocol that instructs a MIME user agent on how it should display an attached file. The range of valid values for content-disposition are discussed in Request for Comment (RFC) 1806 (see the "References" section of this article). This article focuses on the "attachment" argument, which instructs a user agent (in this case, Internet Explorer) to save a file to disk instead of saving it inline.

When Internet Explorer receives the header, it raises a File Download dialog box whose file name box is automatically populated with the file name that is specified in the header. (Note that this is by design; there is no way to use this feature to save a document to the user's computer without prompting him or her for a save location.)

There are two ways that you can use Internet Explorer to specify a content-disposition header for a file: dynamically and statically.

To apply the header dynamically, create an Active Server Pages (ASP) file that writes the document out to the browser. Use the Response.AddHeader method to add the content-disposition header. For example:
Response.AddHeader "content-disposition","attachment; filename=fname.ext"
				
Instructions on how to perform a binary write for nontext documents are available in the following Microsoft Knowledge Base article:
193998 How to read and display binary data in ASP
This technique is ideal when you want to protect a document store on your server, especially one that exists outside of the Web root.

To apply the header statically, right-click the document in the Internet Service Manager, and then select Properties. Select the HTTP Headers tab and enter the content-disposition header there. This works best when you only want to apply content-disposition to a few files on your system and don't require the overhead of ASP.

Please note that this solution will not work in Internet Explorer 4.01 due to a bug. For additional information, click the following article number to view the article in the Microsoft Knowledge Base:
182315 FIX: Content-Disposition: Does not force File Download dialog

REFERENCES

For more information about content-disposition, see Request for Comments (RFC) 1806 at the following Internet Engineering Task Force (IETF) Web site:
http://www.ietf.org/rfc/rfc1806.txt
For more information about developing Web-based solutions for Microsoft Internet Explorer, visit the following Microsoft Web sites:
http://msdn2.microsoft.com/en-us/ie/default.aspx

http://support.microsoft.com/iep

Properties

Article ID: 260519 - Last Review: December 25, 2006 - Revision: 4.1
APPLIES TO
  • Microsoft Internet Explorer 5.0
  • Microsoft Internet Explorer 5.01
  • Microsoft Internet Explorer 5.5
Keywords: 
kbhowto kbnavigation KB260519
Retired KB Content Disclaimer
This article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.

Give Feedback

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com