Question How to load Crystal Report from string name?

Adagio.hpt

New member
Joined
Oct 3, 2014
Messages
4
Programming Experience
5-10
I have a need for a method that receives a string (e.g. CrystalReport1) and returns a ReportClass instance of the report with the specified name. I decided to test if this could be done, but came up with nothing but exceptions
the code I have is like this:

C#:
ReportClass t = new ReportClass();
            
t.Load("CrystalReport1.rpt");

Running this code I get this error: Unable to find the report in the manifest resources. Please build the project, and try again.

The following code works just fine, there is nothing wrong with the report

C#:
CrystalReport1 t = new CrystalReport1();

I have googled the error and all solutions I have found refers to a problem with FullResourceName if there was a space in the directory, but that is not the case here.
Others have mentioned I could try to copy the rpt file to a different directory, remove it from the project and then add existing file to add the rpt file again, but also this didn't do any difference.
I also tried to change the Build action to None, but not much help there.
I have tried to change different ways to load (e.g. also include namespace in load), but no luck

Anybody who has any idea what I could be doing wrong here?

This is Visual Studio 2010 with Crystal Reports v13.0.2000.0


EDIT:

After some further testing I managed to get it working. The code was changed to this:

C#:
ReportDocument t = new ReportDocument();

t.Load(Environment.CurrentDirectory + "\\CrystalReport1.rpt");

And I changed the report to always copy to output directory
 
Last edited:
Back
Top Bottom