0
votes

I am trying to export a crystal report to a pdf file that takes in a user-specified start-date and end-date. The report has default values for these parameters, and it exports without issue if I try it using those default values.

However, when i try to specify the parameters, the ExportToStream() function throws the error "the system cannot find path specified".

Code:

string startDateParm = "2018-01-01";
string endDateParm = "2018-01-31";

ReportDocument rd = new ReportDocument();
rd.Load(Path.Combine(Server.MapPath("~/Reports/ReportExample.rpt")));
rd.SetParameterValue("Start Date", startDateParm);
rd.SetParameterValue("End Date", endDateParm);
Response.Buffer = false;

Stream stream = rd.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
2

2 Answers

0
votes

Try changing

rd.Load(Path.Combine(Server.MapPath("~/Reports/ReportExample.rpt")));

to

rd.Load(Path.Combine(Server.MapPath(@"~/Reports/ReportExample.rpt")));

or

rd.Load(Path.Combine(Server.MapPath(@"{DRIVE:/{folder}/Reports/ReportExample.rpt")));
0
votes

Figured it out. I am still not sure what the exact issue was, but it had something to do with the default values for the parameters. Steps to solve in VS2013:

  1. Open report file in solution
  2. Select "Main Report Preview"
  3. Uncheck the checkbox labeled "Save data in the report".