Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1605
Exporting a report to PDF and then opening it for the user in ASP.Net 2.0
posted

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

Parents
No Data
Reply
  • 40
    Verified Answer
    posted

    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")

    Response.AddHeader(

    "content-length", memStream.Length.ToString())

    Response.ContentType =

    "application/pdf"

    memStream.WriteTo(Response.OutputStream)

     

     

    Response.End()

     

Children