如何禁用从c#.Net在浏览器中弹出的下载

时间:2013-08-16 09:37:55

标签: asp.net c#-3.0

我已将pdf下载添加到我的应用程序中。当我点击下载时,浏览器会询问是保存还是打开pdf文档。但我需要将open设置为默认值,以便下次不会提示。

这是我的代码:

Response.ContentType = "application/pdf";
Response.AppendHeader("Content-Disposition","attachment; filename=" + "Report.pdf");
Response.TransmitFile(pdfFileName);

2 个答案:

答案 0 :(得分:1)

您无法控制它,在您的客户端浏览器范围内处理它。

答案 1 :(得分:0)

希望它会对你有所帮助。 首先将附件文件转换为缓冲区..

        Byte[] buffer = client.DownloadData(path);

        if (buffer != null)
        {
            Response.ContentType = "application/pdf";
            Response.AddHeader("content-length", buffer.Length.ToString());
            Response.BinaryWrite(buffer);
        }