简体   繁体   English

从 CrystalReportViewer 按钮将 Crystal 报表导出为 PDF(使用 Asp.net c#)

[英]Export Crystal report to PDF from CrystalReportViewer button (using Asp.net c#)

I have an ASP.net web application in C#.我在 C# 中有一个 ASP.net Web 应用程序。

The export button and the print button in the toolbar is not working.工具栏中的导出按钮和打印按钮不起作用。

When I click on Print/Export button, dialogue box appear which have option to select pages or select format then i click on export button no file download or save.当我点击打印/导出按钮时,会出现对话框,其中有选择页面或选择格式的选项,然后我点击导出按钮没有文件下载或保存。

paramField.Name = "@GatePass";

paramDiscreteValue.Value = GPLabel.Text;
paramField.CurrentValues.Add(paramDiscreteValue);
paramFields.Add(paramField);
CrystalReportViewer1.ParameterFieldInfo = paramFields;
reportdocument.Load(Server.MapPath("DO_Report.rpt"));
reportdocument.SetDatabaseLogon("sa", "Admin1");

CrystalReportViewer1.ReportSource = reportdocument;
CrystalReportViewer1.DataBind();

I have tried exporttodisk code as well like,我也尝试过 exporttodisk 代码,

reportdocument.ExportToDisk(ExportFormatType.Excel,"C:/Users/Administrator/Desktop/ashar.pdf");

but this code just export the blank report on given destination, i already tried (ExportToHttpResponse) but no solution found, help me please Thanks in Advance但是此代码只是导出给定目的地的空白报告,我已经尝试过(ExportToHttpResponse)但没有找到解决方案,请帮助我提前致谢

Try exporting it as a memory stream maybe.尝试将其导出为内存流。 Also I think there's a printToPrinter method on ReportDocument我还认为 ReportDocument 上有一个 printToPrinter 方法

I found this on SAP site.我在 SAP 网站上找到了这个。 Because the export does a postback, you have to save the session information:由于导出会回发,因此您必须保存会话信息:

    if (!Page.IsPostBack)
    {
        ReportDocument report = new ReportDocument();

        report.Load(Server.MapPath(@"~/Reports/MyReport.rpt"));
        report.SetDatabaseLogon("User", "Password", "server", "database");
        Session.Add("u201Creportu201D", report);
        CrystalReportViewer1.ReportSource = report;
    }
    else
    {
        CrystalReportViewer1.ReportSource = Session["u201Creportu201D"];
    }

https://answers.sap.com/questions/6790184/reportdocumentsetdatabaselogon-not-working-on-dril.html https://answers.sap.com/questions/6790184/reportdocumentsetdatabaselogon-not-working-on-dril.html

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

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