2

我试图用谷歌搜索我的问题,但我没有找到任何关于我的问题的信息。

当我使用 ReportViewer 导出报告时,我想从 Reporting Services 动态重命名报告。基本上,格式将是reportName + timestamp.

有没有使用 C# 或 Reporting Services 本身来做到这一点?

以下是我在我的页面上包含 reportviewer 的方式:

<rsweb:ReportViewer ID="rv" runat="server" ShowToolBar="true" ShowParameterPrompts="false"
    BackColor="#F0F8FF" Height="1200px" Width="100%" ProcessingMode="Remote" EnableViewState="true"
    Visible="false" SizeToReportContent="True">
    <LocalReport EnableExternalImages="True">
    </LocalReport>
</rsweb:ReportViewer>
4

3 回答 3

7

@Devester - 非常感谢您发布解决您自己问题的方法。我们对此表示赞赏,并使我们其他人更容易!

因此,从您的领导来看,我发现在我使用本地报告(即没有报告服务)的解决方案中,这是我需要添加的唯一一行,以从通常导出为 PDF 的“MyReport.rdlc”更改为“MyReport” .pdf”转换为其他内容:

this.rptViewer.LocalReport.DisplayName = _reportName +"_"+ DateTime.Now.ToString("yyyyMMdd HH:mm");

于 2015-02-07T01:48:21.877 回答
3

我用一个简单的方法解决了这个问题,我希望能够用下面的代码帮助别人:

    protected void btnCreate_Click(object sender, System.EventArgs e)
    {
        if (ddlExportFormat.SelectedIndex != 0)
        {
            ExportReport(ddlExportFormat.SelectedValue);
            btnShow_Click(sender, e);
        }
    }

    private void ExportReport(String format)
    {
        // Variables
        Warning[] warnings;
        string[] streamIds;
        string mimeType = string.Empty;
        string encoding = string.Empty;
        string extension = string.Empty;

        string fileName = _reportName +"_"+ DateTime.Now.ToString("yyyyMMdd HH:mm"); 


        // Setup the report viewer object and get the array of bytes
        ReportViewer viewer = new ReportViewer();
        viewer.ProcessingMode = ProcessingMode.Local;

        viewer.ServerReport.ReportServerUrl = new System.Uri(_reportServerUrl);
        viewer.ServerReport.ReportPath = _reportPath;

        if (this.PrepareReportParameters())
        {
            viewer.ServerReport.SetParameters(lstReportParameters);
        }


        byte[] bytes = viewer.ServerReport.Render(format, null, out mimeType, out encoding, out extension, out streamIds, out warnings);


        // Now that you have all the bytes representing the PDF report, buffer it and send it to the client.
        Response.Buffer = true;
        Response.Clear();
        Response.ContentType = mimeType;
        Response.AddHeader("content-disposition", "attachment; filename=" + fileName + "." + extension);
        Response.BinaryWrite(bytes); // create the file
        Response.Flush(); // send it to the client to download
    }

归功于http://beta.codeproject.com/Questions/277989/How-to-export-rdlc-report-to-PDF-without-using-Rep

于 2012-11-30T15:13:51.097 回答
0

它只是一行代码 RptViewer.ServerReport.DisplayName = "Your File Name Goes Here";

于 2016-12-24T06:05:56.540 回答