Loading a Crystal Report Template

Experts

I'm am trying to export a crystal report to pdf.

Here is the code I'm using:

Dim CrystalReportDocument As ReportDocument
        Dim CrystalExportOptions As ExportOptions
        Dim CrystalDiskFileDestinationOptions As DiskFileDestinationOptions

        Dim Filename As String
        CrystalReportDocument = New ReportDocument
        CrystalReportDocument.Load("SimpleReportExport.rpt")

        Filename = "C:\Inetpub\wwwroot\WebApplication2\Foo.pdf"

        CrystalDiskFileDestinationOptions = New DiskFileDestinationOptions
        CrystalDiskFileDestinationOptions.DiskFileName = Filename
        CrystalExportOptions = CrystalReportDocument.ExportOptions
        With CrystalExportOptions
            .DestinationOptions = CrystalDiskFileDestinationOptions
            .ExportDestinationType = ExportDestinationType.DiskFile
            .ExportFormatType = ExportFormatType.PortableDocFormat
        End With
        CrystalReportDocument.Export()

I cannot get the report itself to load.  I have tried using the full path, i have tried not using the full path.  When I use the full path I get the following error:

System.Runtime.InteropServices.COMException: Failed to open report.

This is a basic report that I got from BusinessObjects.com.  I'm just using it as a test for exporting to PDF.  Please help.
lsrbbyAsked:
Who is Participating?
 
cyberdevil67Connect With a Mentor Commented:
Ok when you run the program, the report will need to be in the same directory as the exe is.

Otherwise the full path will not work... however in time if you wish to deploy using a setup package as I have done then you can use the following code.

        Dim filePath As String = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName
        Dim Path As String = filePath.Substring(0, filePath.LastIndexOf("\")) + "\reports\"
        Report.Load(Path + "siInvoicePrint.rpt")

Hope that helps...
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.