首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >RDLC直接导出PDF代码后?

RDLC直接导出PDF代码后?
EN

Stack Overflow用户
提问于 2015-05-22 09:49:28
回答 1查看 4.9K关注 0票数 0

我有一点经验,really.Is可以直接从文件后面的代码导出到PDF,而无需首先显示reportviewer,用户也不必单击导出按钮?我正在使用本地报告处理。谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-05-28 15:37:56

尝尝这个。

代码语言:javascript
复制
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();
    }
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30393543

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档