Crystal Reports: Fix for "Load report failed" error when converting to pdf
When i was working on Crystal Report with Visual Studio 2008 vb.net 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()
'CrystalReportViewer1.Dispose()
'cr.Close()
' cr.Dispose()
''code for load
Dim thefile As String = "F:\winAppCR1" & "\reports\CrystalReport2.rpt"
cr.Load(thefile)
CrystalReportViewer1.ReportSource = cr
CrystalReportViewer1.Refresh()
''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")
cr.Export()
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
Try
'Export the report
cr.Export()
Catch err As Exception
MessageBox.Show(err.ToString())
End Try
End Sub
Comments