我做的是MVC ASP.NET网站,在那里我必须整合FedEx航运。我必须打开该过程的末尾,这是在运输过程中创建的PDF。但是它不能在网站服务器上打开。它在本地运行得很好。我的代码如下所示。请帮帮我
private static void SaveLabel(string labelFileName, byte[] labelBuffer)
{
// Save label buffer to file
FileStream LabelFile = new FileStream(labelFileName, FileMode.Create);
LabelFile.Write(labelBuffer, 0, labelBuffer.Length);
LabelFile.Close();
// Display label in Acrobat
DisplayLabel(labelFileName);
}
private static void DisplayLabel(string labelFileName)
{
System.Diagnostics.ProcessStartInfo info = new System.Diagnostics.ProcessStartInfo(labelFileName);
info.UseShellExecute = true;`enter code here`
info.Verb = "open";
System.Diagnostics.Process.Start(info);
}发布于 2014-09-22 15:16:38
它现在可以在网站上工作了。System.Diagnostics.Process.Start用于在系统上运行perticular程序。您正在服务器上运行该程序,因此文件将在服务器上打开,而不是在浏览器上打开。在浏览器中打开pdf文件方法错误。
正确的方法是返回操作类型为文件或FileStreamResult:
public FileStreamResult PDFGenerator()
{
///byte[] labelBuffer generate the buffer from pdf
MemoryStream ms = new MemoryStream();
ms.Write(labelBuffer, 0, labelBuffer.Length);
ms.Position = 0;
return new FileStreamResult(ms, "application/pdf");
}https://stackoverflow.com/questions/25968274
复制相似问题