RDLC 导出直接在 PDF 代码后面?

RDLC export directly in PDF code behind?

我有一点经验 really.Is 是否可以直接从代码隐藏文件导出为 PDF 而无需先显示报告查看器且用户无需单击导出按钮?我正在使用本地报告处理。谢谢!

试试这个。

protected void showReport(string fileName)
    {
        Warning[] warnings;
        string[] streamIds;
        string mimeType = string.Empty;
        string encoding = string.Empty;
        string extension = string.Empty;
        DataTable DataTable1 = new DataTable
        report.LocalReport.Refresh();
        report.Reset();
        report.LocalReport.EnableExternalImages = true;
        this.report.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Local;
        ReportDataSource rds2 = new ReportDataSource("DataSet1", DataTable1);
        report.LocalReport.DataSources.Add(rds2);
        report.LocalReport.ReportPath = "YourReport.rdlc";
        ReportParameter rptParam = new ReportParameter("your_parameter");       
        report.LocalReport.SetParameters(rptParam);
        byte[] bytes = report.LocalReport.Render("PDF", null, out mimeType, out encoding, out extension, out streamIds, out warnings);
        Response.Buffer = true;
        Response.Clear();
        Response.ContentType = mimeType;
        Response.AddHeader("content-disposition", "attachment; filename=" + fileName + "." + extension);
        try
        {
            Response.BinaryWrite(bytes);
        }
        catch (Exception ex)
        { 
           Page.ClientScript.RegisterStartupScript(this.GetType(), "ErrorAlert", "alert('Error while generating PDF.');", true);
           Console.WriteLine(ex.StackTrace);
        }
        Response.Flush();
        report.LocalReport.Refresh();
    }