Wednesday, July 23, 2008

How To Raise a "File Download" Dialog Box

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

Content-disposition is an extension to the MIME protocol that instructs a MIME user agent on how it should display an attached file.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.

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"

in Java
response.addHeader(CONTENT_DISPOSITION, conditionalParse(contentDisposition, invocation));

1 comment:

Unknown said...

hello sir,
Can u plz explain this concept as if m totaly unaware of these and m new,i mean in general.wat should i ve to do to raise a dialog box for scheduling the downloading.
plz help.