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.
Never mind on this issue; it turned out to be something else. Thanks.
Hi again
I have now tried to open the Acrobat Reader application of the client using the code above but I get an error thrown:
A potentially dangerous Request.Form value was detected from the client
Do you know why this happens? Again, I do not get this when I run the project from VS2008 on my machine; only on IIS.
Yep that worked
'trigger a full postback so Response.xxxxx can be performed
ScriptManager1.RegisterPostBackControl(btnPrintOrders)
You should have the server call be made through a full-page postback, rather than an AJAX callback handled by the UpdatePanel (or by our WebAsyncRefreshPanel).
Since your response will itself be a PDF file, rather than a regular HTML postback response (or AJAX-related XML), it shouldn't cause an actual refresh of your page.
Now how should this method be modified when using an Ajax UpdatePanel since the Response.Writes will not work?