繁体   English   中英

Crystal Report导出为PDF无效

[英]Crystal Report Export to PDF not working

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

感谢您的帮助。 此外,是否还有其他更优化的方法可以将参数传递给报表?

根据您要将其导出到的位置,尝试执行以下操作将其保存到磁盘:

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

希望能有所帮助,

克里斯

编辑:

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

  rd.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, false, 
 "Invoice" + parameter + ".pdf");

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM