I have developed a web application in ASP.Net 2.0. I am preparing a report and am trying to know publish it and open it on screen for the user to view it. I am using the following lines (r is my report)
try
{
r.Publish(
"c:\\Report", FileFormat.PDF);
System.Diagnostics.
Process.Start("Report.pdf");
}
catch (Exception ex)
throw(new Exception("Cannot produce report: " + ex.Message));
While this works fine on my development machine (I get Acrobat to open and view the PDF file), when deployed on the server the PDF file is created but the application is not started for the user to view the document. Furthermore, no exception is captured in the above code.
Can anyone help please?
Thanks
Chris
I used a memory stream so I didn't have to save the file.
Dim memStream As New System.IO.MemoryStream
r.Publish(memStream, Report.FileFormat.PDF)
Response.ClearHeaders()
Response.AddHeader(
"content-disposition", "attachment; filename=file.pdf")
"content-length", memStream.Length.ToString())
Response.ContentType =
"application/pdf"
memStream.WriteTo(Response.OutputStream)
Response.End()
The solution suggested by jsk01 is the correct way to go about this. It sends the PDF file from the server to the client as the response.
The reason why this worked on your development machine is because both your server and your client happened to be the same machine. Calling Process.Start() will start the specified process on the server itself, which won't affect the client machien at all.