我试图完成的事情: - 将Crystal Crystal报告直接转到PDF(绕过查看器) - 它需要数据库登录。 - 需要一个参数。它在CR 11申请中显示为“@rpt_args”。 - 此Crystal报表为其结果集调用Store过程。ASP.NET MVC运行水晶报告直接绕过PDF绕过水晶查看器
我的代码:
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");
目前,我得到一个数据库登录失败。我是否正确设置了代码以执行我正在查找的操作?数据库登录失败的任何可能的原因?
感谢,
** **更新
我把它通过VS正与下面的代码(数据库登录错误是一个错字的结果):
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");
我想要输出到新的选项卡或窗口。目前它只是取代当前窗口。
试图做同样的CR 10.5。以下在我的开发框中工作,但不在服务器上: 'ReportDocument doc = new ReportDocument(); – erict
'ReportDocument doc = new ReportDocument(); doc.Load(Server.MapPath(“〜/ app_data/invoice.rpt”)); doc.SetDatabaseLogon(...); ParameterValues xyz = new ParameterValues(); xyz.Add(new ParameterDiscreteValue()。Value = id); doc.DataDefinition.ParameterFields [“Id”]。ApplyCurrentValues(xyz); doc.ExportToDisk(ExportFormatType.PortableDocFormat,Server.MapPath(“〜/ app_data/invoice.pdf”));' 我假设我已经安装在开发中的CR,但不是在服务器上? – erict
嗨,呃。我想你可能需要用“URL.Content”来包装你的路径才能找到正确的路径。防爆。 Url.Content(“〜/ app_data/whkinvc.rpt”) – Elim99