简体   繁体   English

Crystal Report导出为PDF无效

[英]Crystal Report Export to PDF not working

I'm trying to export Crystal report to PDF format from ASP.NET C#. 我正在尝试从ASP.NET C#将Crystal报表导出为PDF格式。 I want it to be downloaded directly to the client. 我希望将其直接下载到客户端。

When I click on the button, nothing happens. 当我单击按钮时,什么也没有发生。

            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");

Appreciate your help. 感谢您的帮助。 Also, Is there any more optimized way for passing parameters to the report? 此外,是否还有其他更优化的方法可以将参数传递给报表?

Depending on where you want to export it to, try this which will save it to disk: 根据您要将其导出到的位置,尝试执行以下操作将其保存到磁盘:

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

Hope that helps, 希望能有所帮助,

Chris 克里斯

EDIT: 编辑:

Try setting your asAttachment parameter to false and see what happens: 尝试将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