Loading a Crystal Report Template

Posted on 2005-04-12
Last Modified: 2008-02-26

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  I'm just using it as a test for exporting to PDF.  Please help.
Question by:lsrbby
    1 Comment
    LVL 9

    Accepted 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

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
    Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now