我正在尝试将 Crystal 报表从 ASP.NET C# 导出为 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");
感谢你的帮助。另外,有没有更优化的方式将参数传递给报告?