Export Report and Use ASP.NET Server.Transfer To A PDF File


I’m using ASP.NET 2005 and VB with Crystal Reports 10

The Crystal Reports topic called “Navigating through Crystal Reports Pages”  had the following comment from frodoman:

“The common workaround I've seen with asp.net is to export the report to PDF format and save it to a temp folder on your web server and then do a server.transfer to the PDF file.  That allows the client browser to open the results in Acrobat reader and print the complete report from there.”

Could someone show me how to do this in ASP.NET VB code?

Who is Participating?
Here's a sample of code I use to export to pdf

Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Imports CrystalDecisions.Web
Imports System.Data

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim crReportDocument As New CrystalDecisions.CrystalReports.Engine.ReportDocument()
        Dim ReportName As String = Request.QueryString("report")

        ReportName = "/Report Files/" & ReportName

        crReportDocument.Load(Server.MapPath("") & ReportName)
        Call LogonReport(crReportDocument)
        If Session("glbReportSelectionString") <> "" Then
            crReportDocument.RecordSelectionFormula = Session("glbReportSelectionString")
            Session("glbReportSelectionString") = ""
        End If
        Session("glbReportSelectionString") = ""
        'crv1.ReportSource = crReportDocument (displayes report in viewer)

        'Export to PDF - Note:  If access to report file denied error need to grant full permissions
        'on Temp Folder, and full permissions to VS Developer on wwwroot
        Dim exportOpts As New ExportOptions()

        exportOpts = crReportDocument.ExportOptions
        exportOpts.ExportDestinationType = ExportDestinationType.DiskFile
        exportOpts.ExportFormatType = ExportFormatType.PortableDocFormat

        'temp file name - Creates a unique file name that can be deleted later
        Dim diskOpts As New DiskFileDestinationOptions()
        Dim strServerPath As String
        Dim strFile As String
        Dim strPDFFile As String
        Dim convertDate As New System.Globalization.GregorianCalendar()
        Dim julianValue As String
        Dim julianYear As String = convertDate.GetYear(Now)
        Dim julianDay As String = convertDate.GetDayOfYear(Now)
        Dim julianTime As String = convertDate.GetSecond(Now)
        julianValue = julianYear + julianDay + julianTime

        strServerPath = Server.MapPath("") & "\temp" '& "\temp"
        strFile = Session.SessionID & julianValue & ".pdf"
        strPDFFile = strServerPath & "\" & strFile

        diskOpts.DiskFileName = strPDFFile
        exportOpts.DestinationOptions = diskOpts
        'Output pdf to Frameset
        Dim ScriptStr As String = "<Script language='javascript'>window.parent.document.frames(2).location.href='temp\\" & strFile & "';</script>"
        'Display pdf in new page
        'Dim ScriptStr As String = "<Script language='javascript'>open('temp\\" & strFile & "');</script>"

DeniseGoodheartAuthor Commented:
Many Thanks for your code janmarini :-)
Glad i could help

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.