【问题标题】:Diplay Converted reportview Report显示转换后的报告视图报告
【发布时间】:2015-02-20 21:04:24
【问题描述】:

我正在尝试显示已转换为 PDF 的报告。我找到了一些可以显示 PDF 的代码,但它需要存储在磁盘上。有没有办法在本地临时存储 PDF 以便读者可以调用它?

这是当前用于打印按钮的代码。

namespace Dispatch311.Views

/// <summary>
/// Interaction logic for PrintDialog.xaml
/// </summary>
public partial class PrintDialog : Window
{
    public PrintDialog()
    {
        InitializeComponent();                       
    }
    public void DisplayReport(int eventID)
    {
        Warning[] warnings;
        string[] streamids;
        string mimeType;
        string encoding;
        string filenameExtention;

        reportViewer.ProcessingMode = Microsoft.Reporting.WinForms.ProcessingMode.Remote;
        ServerReport serverReport = reportViewer.ServerReport;
        reportViewer.ShowParameterPrompts = false;
        serverReport.ReportServerUrl = new Uri("http://sql2008test/reportserver");
        serverReport.ReportPath = "/311Reports/311SingleEvent";
        ReportParameter ID = new ReportParameter();
        ID.Name = "ID";
        ID.Values.Add(eventID.ToString());
        reportViewer.ServerReport.SetParameters(
            new ReportParameter[] { ID });

        byte[] bytes = reportViewer.ServerReport.Render(
            "PDF", null, out mimeType, out encoding, out filenameExtention,
            out streamids, out warnings);

        using (FileStream fs = new FileStream("EventPDF.pdf", FileMode.Create))
        {
            fs.Write(bytes, 0, bytes.Length);
        }

        reportViewer.RefreshReport();
    }


}

【问题讨论】:

    标签: winforms pdf visual-studio-2012 reportviewer filestream


    【解决方案1】:

    修复了我的代码的结尾,使其看起来像这样:

    byte[] bytes = reportViewer.ServerReport.Render("PDF",
                null, out mimeType, out encoding, out filenameExtension, out streamids, out warnings);
            using (FileStream fs = new FileStream("311Event.pdf", FileMode.Create))
            {
                fs.Write(bytes, 0, bytes.Length);
            }
            string fileName = "311Event.pdf";
            System.Diagnostics.Process process = new System.Diagnostics.Process();
            process.StartInfo.FileName = fileName;
            process.Start();
            process.WaitForExit();
    

    这使得 Adob​​e reader 弹出而不是 reportviewer,并在用户退出阅读器时返回到应用程序。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多