Q: loading Crystal report 10 from file

  • Thread starter Thread starter dllhell
  • Start date Start date
D

dllhell

hello all,

this is my code:

LINE_1: CrystalDecisions.CrystalReports.Engine.ReportDocument aRep= new
CrystalDecisions.CrystalReports.Engine.ReportDocument();

LINE_2: aRep.Load("c:\rep1.rpt", OpenReportMethod.OpenReportByTempCopy);

in line_2 whatever option I use in load method error occured {"Load report
failed."}, also I have tryed with "\\c:\rep1.rpt"...

As you can see, I'm newone in c# programming so please be patient with me :)

thanks for help in advance
 
There is only one thing I can see that's wrong, and it's subtle.

A backslash in C# string tells the compiler to interpret the following
character as special. So, when you wrote:

"c:\rep1.rpt"

what the compiler saw was [c] [:] [carriage return] [e] [p] [1] [.] [r]
[p] [t]. So what's that carriage return doing there? Well, it's what
"\r" stands for. In order to get a backslash in a C# string you have to
do one of two things. Either write

"c:\\rep1.rpt" which works because a double backslash in a normal
string resolves to a single backslash (i.e.: "Treat the next character
as special: it's a real backslash."), or

@"c:\rep1.rpt" which works because the @ preceding the opening quote
tells the compiler, "There are no special characters in this string;
treat every character exactly as shown."

So, you should write either:

aRep.Load("c:\\rep1.rpt", OpenReportMethod.OpenReportByTempCopy);

or

aRep.Load(@"c:\rep1.rpt", OpenReportMethod.OpenReportByTempCopy);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top