This is my problem. I load xml from my database and push it to the client using code. But the problem is that the browser automatically opens that xml instead of offering it as a download.
Is there a way to force your browser to download that file and not showing it?
I'm working in a C#, Asp.net environment (with IIS7).
Thx
Open about:preferences -> Applications. On Extensible Markup Language (xml) action, select "Save File".
Simply click the File button (the 3 lines), and click Save Page As. For example, I went to xml-sitemaps.com/sitemap.xml and clicked Save Page As. It saved as XML to my local machine and loaded as such.
protected void DisplayDownloadDialog()
{
Response.Clear();
Response.AddHeader(
"content-disposition", string.Format("attachment; filename={0}", "filename.xml"));
Response.ContentType = "application/octet-stream";
Response.WriteFile("FilePath");
Response.End();
}
This will force to download the file and not display in the browser.
This will work for any file types without requiring to specify any special MIME type.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With