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.
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