1

我正在尝试将 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");

感谢你的帮助。另外,有没有更优化的方式将参数传递给报告?

4

1 回答 1

0

根据您要将其导出到的位置,试试这个会将其保存到磁盘:

rd.ExportToDisk(ExportFormatType.PortableDocFormat, "C:\report.pdf");

希望有帮助,

克里斯

编辑:

尝试将 asAttachment 参数设置为 false,看看会发生什么:

  rd.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, false, 
 "Invoice" + parameter + ".pdf");
于 2013-10-26T14:50:13.417 回答