• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 559
  • Last Modified:

Loading a Crystal Report Template


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

        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

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.
1 Solution
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...

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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