Posted By: chitemerere — 6 Jul 2008 at 1:54pm
I am new to programming. I am writing an application in Visual Basic using Visual Studio 2008. I am trying to create an embedded crystal report within a project which will be used by my main application as an .exe program. My simple code for this embedded report is as follows:
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Public Class Form1
Private TypeIIDMFsReport As ReportDocument
Private Sub ConfigureCrystalReports()
TypeIIDMFsReport = New ReportDocument
Dim reportPath As String = Application.StartupPath _
& "\" & "TypeIIDMFsReport.rpt"
TypeIIDMFsReport.Load(reportPath)
myCrystalReportViewer.ReportSource = TypeIIDMFsReport
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ConfigureCrystalReports()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
ConfigureCrystalReports()
End Sub
End Class
I tested the application by putting the report in the bin\debug folder, running it and works well
The build action property of the report has been set to embedded resource. I have added a setup project for the windows application which i then built. However, i am getting a report load exception, specified file cannot be located. I thought that at compile time, the report is copied to the same folder as my application's .exe file?
Can someone please assist me with what i need to do to resolve this exception.
Many thanks and kind regards.
Posted By: BrianBischof — 8 Jul 2008 at 8:26pm
I think there is a little confusion on what an embedded report is. When
you create a Windows application with a Crystal Reports, it embeds the
report binary into the application and create a class that represents
the report. You can then declare a variable of this class name,
instantiate it, and assign it to the viewer.
However, looking at your code I see that you are using the Load()
method and referencing the report via its fully qualified filename.
This is the non-embedded method of loading a report. (As a side note,
this is the only way of loading a report that is supported by ASP.NET).
However, Windows apps do allow it.
So if you want to use the report class, declare and instantiate a
report object and use it. Then you don't have to worry about your
setup.exe file. On the other hand, if you want to call the Load()
method, then you need to manually add the report to your setup project
and specify the location to install it.
If you are new to Crystal Reports, I have complete coverage with sample code of using embedded and non-embedded reports in my books. You can find out more about my books at
Amazon.com
or reading the
Crystal
Reports eBooks online.
Posted By: chitemerere — 9 Jul 2008 at 12:27am
Dear Brian
Many thanks for your reply. I was indeed confused with the embedded and non-embedded report issue. However, after some further reading, I managed to sort out the problem by using the non-embedded route and calling the report through a specific file path.
I will definitely buy one of your books on Crystal Reports.
Many thanks and kind regards.