【问题标题】:ASP.NET Send PDF File from Remote share to user to openASP.NET 将 PDF 文件从远程共享发送给用户以打开
【发布时间】:2013-08-28 18:16:57
【问题描述】:

所以我的代码正在生成 PDF 报告并将其发布到远程文件共享服务器,所有这些都正常工作,所以我知道我对共享具有适当的读/写访问权限。

现在我正在尝试创建一个“打开 PDF”按钮,该按钮基本上只是将远程共享中的文件提供给用户,这样用户就可以打开 PDF 并查看它,而无需转到文件共享本身并进行挖掘它。

我尝试了一些方法,但无论我做什么都会出错。

我试过这段代码,当它在我的 ASP.NET 服务器上时,我用来提供文件并且工作正常,但是当我给它一个远程文件时它不会工作。

Response.Clear();
Response.ContentType = "Application/pdf";
Response.AppendHeader("Content-Disposition", "attachment; filename=Report_Submission_" +   SubmissionID + ".pdf");
String filePath = "\\\\Fileserver\\Directory1\\Directory2\\Directory3" +       "\\Report_Submission_" + SubmissionID + ".pdf";
Response.TransmitFile(filePath);
Response.End();

使用我得到以下异常 0x800a139e - Microsoft JScript 运行时错误:Sys.WebForms.PageRequestManagerParserErrorException:无法解析从服务器接收到的消息。

我也试过这样做

Response.ContentType = "application/pdf";
Response.WriteFile(filePath);

我得到了同样的例外。

我已经试过了

Response.Redirect(filePath);

但这也不起作用。

我尝试做的事情可能吗?您可以在不先将文件复制到本地服务器的情况下从远程文件共享中提供文件吗?

【问题讨论】:

标签: c# asp.net pdf


【解决方案1】:

试试这个。

Response.AddHeader("Content-Type", "application/octet-stream");

Response.AddHeader("Content-Transfer-Encoding","Binary"); 

Response.AddHeader("Content-disposition", "attachment; filename=\"sample.pdf\"");

Response.WriteFile(HttpRuntime.AppDomainAppPath + @"path\to\file\sample.pdf");

Response.End();

【讨论】:

    猜你喜欢
    • 2011-11-25
    • 2019-10-21
    • 2012-04-20
    • 2023-03-18
    • 1970-01-01
    • 1970-01-01
    • 2018-05-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多