Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Writing a pdf on an asp.net page 1

Status
Not open for further replies.

ashstampede

Programmer
Aug 30, 2004
104
GB
I have pdf files that are exproted from a crystal report, i can succesfully export and write to file the crystal report -> pdf. but when i then want to show it in the browser to the user nothing apprears.
this is my export,save,write to browser code
Code:
'export dataset to pdf file for printing
            Dim Fname As String
            Fname = Server.MapPath("exports/" & Session.SessionID.ToString & ".pdf")
            Dim crExO As ExportOptions = report.ExportOptions
            Dim crDFDO As DiskFileDestinationOptions = New DiskFileDestinationOptions

            crExO.ExportFormatType = ExportFormatType.PortableDocFormat
            crExO.ExportDestinationType = ExportDestinationType.DiskFile
            crExO.DestinationOptions = New DiskFileDestinationOptions
            crDFDO.DiskFileName = Fname
            report.ExportOptions.DestinationOptions = crDFDO
            report.Export()
            ' The following code writes the pdf file to the Client’s browser.
            Response.ClearContent()
            Response.ClearHeaders()
            Response.ContentType = "application/pdf"
            Response.WriteFile(Fname)
            Response.Flush()
            Response.Close()
           
            'delete the exported file from disk
            'System.IO.File.Delete(Fname)
 
thanks for the suggestion dace, but still a no go. no errors are thrown or anything. Just no pdf displayed
 
Hmm.. something else to try- comment out the line that deletes the report afterward. It might be deleting the report before the client grabs it.
 
Whoops, sorry, it was. Back to the drawing board.
 
The only difference between your code and working code I use to export Crystal Reports reports in pdfs is that I use Clear instead of ClearContents and ClearHeaders, I add headers, and I End the response instead of Flush and Close.

Headers I use:
Code:
Response.AddHeader("Content-Disposition", "attachment;filename=_______
Response.AddHeader("Content-Length", ____.Length.ToString())


 
wow thanks, that worked. However it ask me to download it instead of just displaying it in the browser. Do you display yours in the browser or the user has to save it as well?
 
If you want it to display in the browser, try changing the Content-Disposition header to be "inline" instead of "attachment" - that should do it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top