Crystal Reports: Fix for "Load report failed" error when converting to pdf

When i was working on Crystal Report with Visual Studio 2008 application , i got the load report failed error when converting to pdf format. using vista os.
(when i shifted to server 2008 same code works fine. vista has some issues related to security)
Here is the code throwing error at cr.Load(thefile)

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        'Dim cr As New ReportDocument
        Dim cr As ReportDocument = New CrystalDecisions.CrystalReports.Engine.ReportDocument()
        ' cr.Dispose()
        ''code for load
        Dim thefile As String = "F:\winAppCR1" & "\reports\CrystalReport2.rpt"
        CrystalReportViewer1.ReportSource = cr

        ''code for export
        Dim x_opt As ExportOptions = cr.ExportOptions
        x_opt.ExportFormatType = ExportFormatType.PortableDocFormat
        x_opt.ExportDestinationType = ExportDestinationType.DiskFile
        x_opt.DestinationOptions = New DiskFileDestinationOptions()
        Dim hdd_opt As New DiskFileDestinationOptions()

        CType(cr.ExportOptions.DestinationOptions, DiskFileDestinationOptions).DiskFileName = ("c:\vin.pdf")

    End Sub

I replaced above code with below code. I just didnot show the report and directly convert it to pdf .

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim cr As New mou_summary()
        Dim CrExportOptions As ExportOptions
        Dim CrDiskFileDestinationOptions As New DiskFileDestinationOptions()
        Dim CrFormatTypeOptions As New PdfRtfWordFormatOptions()

        'Set the destination path and file name

        CrDiskFileDestinationOptions.DiskFileName = "c:\RichText.pdf"

        'Specify a page range (optional)

        CrFormatTypeOptions.FirstPageNumber = 1 ' Start Page in the Report

        CrFormatTypeOptions.LastPageNumber = 3 ' End Page in the Report

        CrFormatTypeOptions.UsePageRange = True

        'Set export options

        CrExportOptions = cr.ExportOptions

        With CrExportOptions

            'Set the destination to a disk file

            .ExportDestinationType = ExportDestinationType.DiskFile

            'Set the format to PDF

            .ExportFormatType = ExportFormatType.PortableDocFormat

            'Set the destination options to DiskFileDestinationOptions object

            .DestinationOptions = CrDiskFileDestinationOptions

            .FormatOptions = CrFormatTypeOptions

        End With

        'Trap any errors that occur on export


            'Export the report


        Catch err As Exception


        End Try
    End Sub


Most Viewed Post

solution for facebook waiting

Connect Sony XPLOD MEX-BT2500 Bluetooth CD Receiver with ur mobile

Crystal Report : Show data horizontally (Left to right) i.e. columns as rows

Google+ Followers