1
votes

I am trying to use crystal report with asp mvc first time but I have some problem to load report:

ReportClass rptH = new ReportClass();
            rptH.FileName = Server.MapPath("Reports/TestReport.rpt");
            rptH.Load();

This is value of rptH.FileName

"rassdk://D:\\ProjectDir\\Pro\\Pro.WebUI\\Reports\\TestReport.rpt"

But on Load() I get exception:

Load report failed.

Report doesn't have any datasource it's just blank report with some text.
Maybe it's important. I set project to run on local IIS (not in VS).



UPDATE

I have changed code a little bit and now I get some other error (I also copied project in inetpub/wwwroot). This is the error:

Value cannot be null. Parameter name: path2

And path now is:

"C:\\inetpub\\wwwroot\\MyProject\\Pro\\Pro.WebUI\\Reports\\TestReport.rpt"

New code is:

ReportClass rptH = new ReportClass();
            var path = Server.MapPath("Reports/TestReport.rpt");

            rptH.Load(path);
3
Can somebody at least suggest where can I look for problem. I don't have any idea any more. - 1110

3 Answers

0
votes

I've done a Crystal Report with ASP.NET before. Not sure if you're able to do this or not, but it worked successfully for me.

 ReportDocument rptDoc = new ReportDocument();
 rptDoc.Load(Server.MapPath("TestReport.rpt");

 Response.Buffer = False
 Response.ClearContent()
 Response.ClearHeaders()

 rptDoc.ExportToDisk(ExportFormatType.PortableDocFormat, "TestReport.rpt")
 rptDoc.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, True, "MyReport")
0
votes

Check the rpt file if there are parameters defined. If there are and you do not need them then remove it. If you need them then supply them values and description in code. Exp:

rep = new ReportDocument();
string reportPath = Server.MapPath("Reports/TestReport.rpt");
rep.Load(reportPath);
rep.SetParameterValue(0, "SomeValue");
crViewer.ReportSource = rep;
crViewer.ParameterFieldInfo[0].CurrentValues[0].Description = "ParameterName";
crViewer.DataBind();
0
votes

Try this

  ReportDocument rd = new ReportDocument();
  string FileName = Server.MapPath("~/Report") + "//YourReportName.rpt";
  rd.Load(FileName);
  rd.SetDataSource(dt);