Latest Art Work

Friday, May 09, 2008

ASP.Net - Close window after download prompt

Source: Madalina's Blog

I spent the whole morning before I finally found my solution in this blog. Eternally grateful for such a simple solution considering I tried everything from javascript to startupscript.

As quoted:
So what is the answer? It is simple yet not easy to be found - because you always have in mind the premise that the user must have the option of Opening/Saving the file. The answer is:

Response.AddHeader("Content-Disposition", "inline; filename=" + [file].NewFileName);

How come? Well, if you select Inline, the application will try to write the file directly to the browser. If the browser has a plugin for that type of file (for eg PDFs) the file will be opened in the new window. (Y) If the user wants to save it, the plugin has a menu bar and options for saving on disk. If the browser does not have a plugin for the file, the Open Save dialog will appear and upon any choice the new empty window will be automatically closed.

adapted from Madalina's Blog

0 comments: