我試圖完成的事情: - 將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