What I'm trying to accomplish: - Run Crystal Report straight to PDF (bypassing the viewer) - It requires a database login. - It takes one parameter. It shows as '@rpt_args' in CR 11 application. - This Crystal report calls a Store procedure for it's result set.
My code:
ReportClass rptH = new ReportClass();
//rptH.FileName = Server.MapPath("whkinvc.rpt");
rptH.FileName = "D:\\whkinvc.rpt";
rptH.Load();
rptH.SetDatabaseLogon("FAKEUSER", "FAKEPASSWORD", "FAKESERVER", "FAKEDB");
rptH.SetParameterValue("@rpt_args", atm.WorkingModel.Header.TicketNumber);
Stream stream = rptH.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
return File(stream, "application/pdf");
I'm currently getting a database login failure. Do I have my code setup correctly to perform the action I'm looking for? Any possible reason for the database login failure?
Thanks,
** Update **
I got it working through VS with the following code (The database login error was of result of a typo):
ReportClass rptH = new ReportClass();
rptH.FileName = Server.MapPath(Url.Content("~/app_data/whkinvc.rpt"));
rptH.Load();
rptH.SetDatabaseLogon(...);
ParameterValues xyz = new ParameterValues();
ParameterDiscreteValue pdv = new ParameterDiscreteValue();
pdv.Value = atm.WorkingModel.Header.TicketNumber;
xyz.Add(pdv);
rptH.DataDefinition.ParameterFields["@rpt_args"].ApplyCurrentValues(xyz);
Stream stream = rptH.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
return File(stream, "application/pdf");
I would like the output to go to a new tab or window. Currently it just replaces the current window.