【发布时间】:2010-12-21 04:00:06
【问题描述】:
我从数据库中检索了 pdf 文件并将其链接到“a href”标签以使用链接打开 pdf 文件。现在我想在打开 pdf 文件之前给出打开/保存对话框。 - 在javascript中(通过使用“a”标签中的onclick事件来调用javascript)
【问题讨论】:
标签: c# asp.net javascript pdf file-upload
我从数据库中检索了 pdf 文件并将其链接到“a href”标签以使用链接打开 pdf 文件。现在我想在打开 pdf 文件之前给出打开/保存对话框。 - 在javascript中(通过使用“a”标签中的onclick事件来调用javascript)
【问题讨论】:
标签: c# asp.net javascript pdf file-upload
您必须使用 C# 设置 content-disposition 标头才能在浏览器中获得此行为。
阅读本文了解更多信息
How do I prompt a "Save As" dialog for an accepted mime type?
Downloading a File with a Save As Dialog in ASP.NET
示例
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName);
Response.AddHeader("Content-Length", targetFile.Length.ToString);
Response.ContentType = "application/pdf";
Response.WriteFile(targetFile.FullName);
【讨论】: