Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

asp.net - Adobe PDF not showing on IIS7

I got this code below working on local (using source code) perfectly fine. But when I published it on IIS7 the PDF is not showing anymore.. Is there a problem with the IIS or ?. . . I spent many days on this problem.

Dim strPath = Server.MapPath("~ReportsGeneratedReport.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

As you can notice in the picture below you see the AdobeReader is running but its not displaying on my screen.

enter image description here

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

When you say "not showing" I am assuming you want the PDF to be opened on the client, not the server. Normally you would send the file to the browser. Process.Start() will start a process server-side, so even if the AppPool is allowed to start a process, it will only open the pdf on the server. Below is how you send a file from the server to the client.

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...