如何强制浏览器下载一个xml文件? [英] How can you force the browser to download an xml file?
本文介绍了如何强制浏览器下载一个xml文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我从我的数据库加载xml,并使用代码将其推送到客户端。
但是问题是浏览器自动打开那个xml,而不是将其作为下载。
有没有办法强制您的浏览器下载该文件没有显示?
我正在一个C#,Asp.net环境(使用IIS7)工作。
Thx
解决方案
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();
}
这将强制下载文件,不显示在浏览器中。 p>
这将适用于任何文件类型
,而不需要指定任何
特殊MIME类型。
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
解决方案
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.
这篇关于如何强制浏览器下载一个xml文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文