我正在尝试从ASP.NET C#导出Crystal报表到PDF格式。我希望将它直接下载到客户端。
当我点击按钮时,没有任何反应。
string parameter = ViewState["strInvoiceID"].ToString();
TableLogOnInfo logOnInfo = new TableLogOnInfo();
logOnInfo.ConnectionInfo.ServerName = System.Configuration.ConfigurationManager.AppSettings["Server"];
logOnInfo.ConnectionInfo.DatabaseName = System.Configuration.ConfigurationManager.AppSettings["Database"];
logOnInfo.ConnectionInfo.IntegratedSecurity = false;
logOnInfo.ConnectionInfo.UserID = System.Configuration.ConfigurationManager.AppSettings["UID"];
logOnInfo.ConnectionInfo.Password = System.Configuration.ConfigurationManager.AppSettings["PWD"];
ReportDocument rd = new ReportDocument();
string reportPath = Server.MapPath("InvoiceReport.rpt");
rd.Load(reportPath);
foreach (CrystalDecisions.CrystalReports.Engine.Table tbl in rd.Database.Tables)
tbl.ApplyLogOnInfo(logOnInfo);
ParameterValues crParameterValues = new ParameterValues();
ParameterDiscreteValue crParameterDiscreteValue = new ParameterDiscreteValue();
crParameterDiscreteValue.Value = parameter;
rd.DataDefinition.ParameterFields["InvoiceID"].CurrentValues.Clear();
crParameterValues.Add(crParameterDiscreteValue);
rd.DataDefinition.ParameterFields["InvoiceID"].ApplyCurrentValues(crParameterValues);
Response.Buffer = false;
Response.ClearContent();
Response.ClearHeaders();
rd.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, true, "Invoice" + parameter + ".pdf");
感谢您的帮助。 此外,还有更优化的方法将参数传递给报告吗?
答案 0 :(得分:0)
根据您要将其导出到的位置,尝试将其保存到磁盘:
rd.ExportToDisk(ExportFormatType.PortableDocFormat, "C:\report.pdf");
希望有所帮助,
克里斯
编辑:
尝试将asAttachment参数设置为false,看看会发生什么:
rd.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, false,
"Invoice" + parameter + ".pdf");