Forcing "Save Taget As" dialog when clicking a link
-
I haven written modules that generates a series XML files and a report in a number of HTML files which include and index etc. What I am having difficulty with is that we would like to be able to click on the name of one of the XML files in the report and get the browser to pop up the Save As dialog, so that it can be copied to a location other than the default. This must be possible. I just haven't found out how as yet. Happy programming!!
-
I haven written modules that generates a series XML files and a report in a number of HTML files which include and index etc. What I am having difficulty with is that we would like to be able to click on the name of one of the XML files in the report and get the browser to pop up the Save As dialog, so that it can be copied to a location other than the default. This must be possible. I just haven't found out how as yet. Happy programming!!
Hi there, The extension .xml is a known type, so the browser by default will open it when the user clicks on the link pointing to the file. If you want to force the File Download dialog box, you may consider using the
Content-Disposition
header field. Instead of using the anchor, you basically use a seperate web page which is responsible for reading the content file of the xml and write out to the Reponse object, and you need to add the Content-Disposition field to the header of the response. With this field, you can suggest a filename which is displayed in the File Download dialog box. -
Hi there, The extension .xml is a known type, so the browser by default will open it when the user clicks on the link pointing to the file. If you want to force the File Download dialog box, you may consider using the
Content-Disposition
header field. Instead of using the anchor, you basically use a seperate web page which is responsible for reading the content file of the xml and write out to the Reponse object, and you need to add the Content-Disposition field to the header of the response. With this field, you can suggest a filename which is displayed in the File Download dialog box.Thanks for you're suggestion. I'll try it out. Incidentally the file I generate does not use the .xml extension. It doesn't seem to matter what the extension is, for IE anyway, the browser checks that the file contains displable text so it displays it. Happy programming!!
-
Hi there, The extension .xml is a known type, so the browser by default will open it when the user clicks on the link pointing to the file. If you want to force the File Download dialog box, you may consider using the
Content-Disposition
header field. Instead of using the anchor, you basically use a seperate web page which is responsible for reading the content file of the xml and write out to the Reponse object, and you need to add the Content-Disposition field to the header of the response. With this field, you can suggest a filename which is displayed in the File Download dialog box.I must be doing something wrong as I can't get it to work. Could you suggest how the HTML is supposed to look. This is not being done via a server. Happy programming!!
-
I must be doing something wrong as I can't get it to work. Could you suggest how the HTML is supposed to look. This is not being done via a server. Happy programming!!
The markup in the html file looks something like:
<a href="Download.aspx?filename=foo.xml" >foo.xml</a>
So you specify the web page in the
href
attribute of the anchor element instead of the foo.xml. Also, you might want to add the name of the xml file to query string so that it can be used later in the web page for reading the file content. In the web page, you programmatically add theContent-Disposition
field to the header of the reponse. In addition, you can also statically add theContent-Disposition
field to the header in the IIS-snapin (Here, I assume you are using the IIS as your web server).