这是在 asp.net 中。
我正在参考用户的输入创建 pdf 文件。
该 pdf 文件保存在服务器上的文件夹中。
现在可以使用response.redirect 在浏览器中显示该文件。
但我想向用户显示“保存文件”对话框(就像我们从网站下载 exe 时看到的那样),以便在本地硬盘中下载并保存相同的文件,而不是在浏览器中打开它。
我怎样才能做到这一点??
Setting Response.ContentType = "application/octet-stream";
通常对我有用。我也用Response.BinaryWrite
以及。有一种哑剧类型application/pdf
(Windows Internet Explorer 中的 MIME 类型检测),所以你也可以尝试一下。
这是一个使用的示例application/pdf
来自微软(如何使用 ASP.NET 和 Visual C# .NET 将二进制文件写入浏览器)
private void Page_Load(object sender, System.EventArgs e)
{
//Set the appropriate ContentType.
Response.ContentType = "Application/pdf";
//Get the physical path to the file.
string FilePath = MapPath("acrobat.pdf");
//Write the file directly to the HTTP content output stream.
Response.WriteFile(FilePath);
Response.End();
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)