我已从数据库中检索了 pdf 文件,并将其链接到“a href”标签以使用链接打开 pdf 文件。现在我想在打开pdf文件之前给出打开/保存对话框。 - 在javascript中(通过使用“a”标签中的onclick事件来调用javascript)
最佳答案
您必须使用 C# 设置 content-disposition header 才能在浏览器中获得此行为。
阅读本文以获取更多信息
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);
关于c# - 在 asp.net 中从 DB- 检索 pdf 文件的链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1811686/