2013-08-28 48 views
2

所以我的代碼生成一個PDF報告並將其發佈到遠程文件共享服務器,所有這些工作,所以我知道我有正確的讀/寫訪問共享。ASP.NET從遠程共享發送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 - 微軟JScript運行時錯誤:Sys.WebForms.PageRequestManagerParserErrorException:從服務器收到的消息無法解析。

我也試着這樣做

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

,我也得到相同的異常。

香港專業教育學院甚至只是試圖

Response.Redirect(filePath); 

但是,這並不工作要麼。

是我試圖做的可能嗎?您可以從遠程文件共享提供文件,而無需先將其複製到本地服務器?

+0

可能重複http://stackoverflow.com/questions/1652792/response-transmitfile-with-unc-share-asp-net ) –

回答

0

試試這個。的[Response.TransmitFile()與UNC共享(ASP.NET)](

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();