thi*_*eek 21
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();
}
Run Code Online (Sandbox Code Playgroud)
这将强制下载文件而不是在浏览器中显示.
这适用于任何文件类型,无需指定任何特殊的MIME类型.