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

Posted on 2006-05-29
Last Modified: 2008-02-01

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 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?

Question by:DeniseGoodheart
    LVL 100

    Assisted Solution

    LVL 7

    Accepted Solution

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


    Author Comment

    Many Thanks for your code janmarini :-)
    LVL 100

    Expert Comment

    Glad i could help


    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Suggested Solutions

    There have always been a lot of questions related to when Crystal Reports evaluates report components (such as formulas, summaries, cross-tabs, charts, to name a few examples). Crystal Reports uses a two-pass reporting process to provide greater …
    Hello everyone, Hope you find this as helpful as we did. We have on the company I work for an application built in Delphi V with Crystal Reports 8. We all know that Crystal & Delphi can be temperamental sometimes and the worst thing is, nearly…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now