2016-03-08 53 views
0

我們有一個需要從服務器的特定位置打開pdf文件的需求,即「C:\ PdfFile \ Test.pdf」。從c#的服務器位置打開pdf文件

我曾嘗試這種解決方案:

  string fileName = lnk.CommandArgument.ToString(); 
      System.Diagnostics.ProcessStartInfo a = new System.Diagnostics.ProcessStartInfo(fileName, "Open"); 
      System.Diagnostics.Process.Start(a); 

這是工作的地方,因爲我們有相同的路徑在我們當地但當我們主辦的網站,這是行不通的。

+0

確定,當您打開服務器上的PDF發生了什麼?誰會看它? – Dalorzo

+0

它在服務器中打開,但我有要求在本地打開它。 –

+1

但具有代碼的應用程序託管在服務器上......一個網站。不在客戶端上。那麼,您如何期望您的代碼根據您的要求來理解? – Dalorzo

回答

2

在你ASP.NET表單應用程序,你必須添加以下代碼:

Response.ContentType = "application/pdf"; 
Response.AppendHeader("Content-Disposition", "attachment; filename=MyFile.pdf"); 
Response.TransmitFile(Server.MapPath(@"C:\PdfFile\Test.pdf")); 
Response.End();