[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 880
  • Last Modified:

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

Hi,

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?

Thanks,
Denise
0
DeniseGoodheart
Asked:
DeniseGoodheart
  • 2
2 Solutions
 
mlmccCommented:
0
 
janmariniCommented:
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
        crReportDocument.Export()
        crReportDocument.Close()
        crReportDocument.Dispose()
       
        '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>"

        Response.Write(ScriptStr)
0
 
DeniseGoodheartAuthor Commented:
Many Thanks for your code janmarini :-)
0
 
mlmccCommented:
Glad i could help

mlmcc
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now