【问题标题】:Link to retrieve pdf file from DB- in asp.net在 asp.net 中从 DB- 检索 pdf 文件的链接
【发布时间】:2010-12-21 04:00:06
【问题描述】:

我从数据库中检索了 pdf 文件并将其链接到“a href”标签以使用链接打开 pdf 文件。现在我想在打开 pdf 文件之前给出打开/保存对话框。 - 在javascript中(通过使用“a”标签中的onclick事件来调用javascript)

【问题讨论】:

    标签: c# asp.net javascript pdf file-upload


    【解决方案1】:

    您必须使用 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); 
    

    【讨论】:

    猜你喜欢
    • 2019-04-28
    • 2010-10-20
    • 2013-09-12
    • 2021-04-02
    • 2012-07-24
    • 2018-08-20
    • 2017-07-20
    • 2019-04-25
    • 2012-09-25
    相关资源
    最近更新 更多