Wenn Sie sagen, „nicht angezeigt“ Ich gehe davon aus Sie die PDF wollen auf dem Client geöffnet werden, nicht der Server. Normalerweise würden Sie die Datei an den Browser senden. startet einen Prozess serverseitig. Selbst wenn der AppPool einen Prozess starten darf, wird nur das PDF auf dem Server geöffnet. Unten sehen Sie, wie Sie eine Datei vom Server an den Client senden.
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
Hallo, ich werde meinen Code nicht mehr verwenden ?. – KiRa
Nicht, wenn Sie eine Datei vom Server auf den Client herunterladen möchten. – VDWWD
Ich habe Ihren Code getestet und funktioniert gut .. Aber es ist das Herunterladen der PDF .. Gibt es alternative Möglichkeit von "Response.Flush"? Genau wie das Anzeigen – KiRa