Loading a Crystal 11 Report.

mike55

Well-known member
Joined
Mar 26, 2004
Messages
726
Location
Ireland
Hi all

I am after creating a report in crystal 11 (trial version), I have unticked the option that saves the data with the report. I am trying to load the report using the code that I have used with crystal reports generated in visual studio.net. My problem is that the report is loading blank, what am I doing wrong?

Here is the code that I am using:
Code:
  Private Sub GenerateReport()

        Dim crystalServer As String = ConfigurationManager.ConnectionStrings("SERVER").ToString
        Dim count As Int16 = 0

start:
        oRpt = New ReportDocument
        Dim util As New Utility
        Dim rptPath As String = Nothing
        Dim requestedHostAddress As String
        requestedHostAddress = Request.UserHostAddress

        Get Report path
        rptPath = Server.MapPath("rptMembers.rpt")
        check the exitence of the file
        If Len(rptPath) = 0 Then
            Exit Sub
        End If
        oRpt.Load(rptPath)
    
        oRpt.DataDefinition.FormulaFields("Org").Text = "" + Session("OrgID") + ""
        oRpt.DataDefinition.FormulaFields("Active").Text = "" + Request.QueryString("Active") + ""
        oRpt.DataDefinition.FormulaFields("User").Text = "" + Request.QueryString("by").Replace("", "`") + ""
        Try
             Generate report  and Export as PDF file
            Dim crLogonInfo As CrystalDecisions.Shared.TableLogOnInfo
            crLogonInfo = oRpt.Database.Tables(0).LogOnInfo
            crLogonInfo.ConnectionInfo.ServerName = crystalServer
            crLogonInfo.ConnectionInfo.DatabaseName = ConfigurationManager.ConnectionStrings("DBNAME").ToString
            crLogonInfo.ConnectionInfo.UserID = ConfigurationManager.ConnectionStrings("USER").ToString
            crLogonInfo.ConnectionInfo.Password = ConfigurationManager.ConnectionStrings("PASS").ToString
            oRpt.Database.Tables(0).ApplyLogOnInfo(crLogonInfo)

             Varables here are used to export the report to PDF
            Dim myExportOptions As CrystalDecisions.Shared.ExportOptions
            Dim myDiskFilesDestinationOptions As CrystalDecisions.Shared.DiskFileDestinationOptions
            Dim myExportFile As String

            myExportFile = "C:\temp\PDF " & Session.SessionID.ToString & ".pdf"
            myDiskFilesDestinationOptions = New CrystalDecisions.Shared.DiskFileDestinationOptions
            myDiskFilesDestinationOptions.DiskFileName = myExportFile
            myExportOptions = oRpt.ExportOptions

             Proceed with the Export
            With myExportOptions
                .DestinationOptions = myDiskFilesDestinationOptions
                .ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.DiskFile
                .ExportFormatType = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat
            End With

            oRpt.Export()

             Clean up resources used
            Response.ClearContent()
            Response.ClearHeaders()
            Response.ContentType = "application/pdf"
            Response.WriteFile(myExportFile)
            Response.Flush()
            Response.Close()

             Delete the temporary file
            System.IO.File.Delete(myExportFile)

        Catch ex As Exception
            oRpt.Dispose()
            If count <= 1 Then
                crystalServer = ConfigurationManager.ConnectionStrings("SERVER_FAILOVER").ToString
                count = +1
            End If
            GoTo start
        End Try
    End Sub
 
Back
Top