2017-04-07 83 views
1

我得到了下面的代碼在本地工作(using source code)完美的罰款。但是,當我發佈它在IIS7PDF不再顯示..是否有問題的IIS或? 。 。我花了很多天在這個問題上。Adob​​e PDF不在IIS7上顯示

Dim strPath = Server.MapPath("~\Reports\GeneratedReport.pdf") 

my_rpt.ExportToDisk(ExportFormatType.PortableDocFormat, strPath) 
Dim file = New System.IO.FileInfo(strPath) 
Dim Process = New Process() 
If file.Exists Then 
    Process.StartInfo.UseShellExecute = True 
    Process.StartInfo.FileName = strPath 
    Process.Start() 
Else 
    'No Report found 
End If 

正如您在下圖中看到的那樣,您會看到AdobeReader正在運行,但它並沒有顯示在我的屏幕上。

enter image description here

回答

1

當你說「沒有顯示」我假設你想要的客戶,而不是在服務器上打開PDF文件。通常你會發送文件到瀏覽器。 Process.Start()將啓動一個進程服務器端,所以即使AppPool被允許啓動一個進程,它也只會在服務器上打開pdf。 下面介紹如何從服務器向客戶端發送文件。

string strPath = Server.MapPath("~/reports/GeneratedReport.pdf"); 

//read the file from disk and convert to a byte array 
byte[] bin = File.ReadAllBytes(strPath); 

//clear the buffer stream 
Response.ClearHeaders(); 
Response.Clear(); 
Response.Buffer = true; 

//set the correct contenttype 
Response.ContentType = "application/pdf"; 

//set the correct length of the data being send 
Response.AddHeader("content-length", bin.Length.ToString()); 

//set the filename for the file 
Response.AddHeader("content-disposition", "attachment; filename=\"GeneratedReport.pdf\""); 

//send the byte array to the browser 
Response.OutputStream.Write(bin, 0, bin.Length); 

//cleanup 
Response.Flush(); 
HttpContext.Current.ApplicationInstance.CompleteRequest(); 

VB

Dim strPath As String = Server.MapPath("~/reports/GeneratedReport.pdf") 

'read the file from disk and convert to a byte array 
Dim bin() As Byte = File.ReadAllBytes(strPath) 

'clear the buffer stream 
Response.ClearHeaders 
Response.Clear 
Response.Buffer = true 

'set the correct contenttype 
Response.ContentType = "application/pdf" 

'set the correct length of the data being send 
Response.AddHeader("content-length", bin.Length.ToString) 

'set the filename for the file 
Response.AddHeader("content-disposition", "attachment; filename=""GeneratedReport.pdf"""")", send the byte array to the browser, Response.OutputStream.Write(bin, 0, bin.Length)) 

'cleanup 
Response.Flush 
HttpContext.Current.ApplicationInstance.CompleteRequest 
+0

你好,我不會再使用我的代碼了嗎? – KiRa

+0

如果您想要將文件從服務器下載到客戶端,則不適用。 – VDWWD

+0

我測試了你的代碼並且工作正常。但是它下載了PDF ..有沒有其他的'Response.Flush'方法?就像顯示它 – KiRa

相關問題