【问题标题】:Exporting SSRS Report to PDF in MVC Action在 MVC 操作中将 SSRS 报告导出为 PDF
【发布时间】:2013-07-23 22:07:22
【问题描述】:

是的,我想将 SSRS 报告导出到 PDF 并从我的操作中返回,我没有任何报告查看器。请建议我如何实现这一点。到目前为止我已经这样做了

    public void SqlServerReport()
    {
        NetworkCredential nwc = new NetworkCredential("username", "password", "domain");
        WebClient client = new WebClient();
        client.Credentials = nwc;
        string reportURL = "http://servername/ReportServer/reportfolder/StateReport&rs:Command=Render&rs:Format=PDF";
        Byte[] pageData = client.DownloadData(reportURL);
        Response.ContentType = "application/pdf";
        Response.AddHeader("Content-Disposition", "attachment; filename=" + DateTime.Now);
        Response.BinaryWrite(pageData);
        Response.Flush();
        Response.End();
    }

以上代码抛出异常

"The remote server returned an error: (401) Unauthorized."

我的问题是
1) 我的方向正确吗?
2) 有没有更好的选择来实现这一目标?

【问题讨论】:

    标签: asp.net-mvc reporting-services export-to-pdf


    【解决方案1】:

    尽量不要这样指定域:

    NetworkCredential nwc = new NetworkCredential("username", "password");
    

    【讨论】:

      【解决方案2】:

      我更正了上面的代码,现在它可以工作了

          public ActionResult GetPdfReport()
          {
              NetworkCredential nwc = new NetworkCredential("username", "password");
              WebClient client = new WebClient();
              client.Credentials = nwc;
              string reportURL = "http://someIp/ReportServer/?%2fReportProjectName/ReportName&rs:Command=Render&rs:Format=PDF";
              return File(client.DownloadData(reportURL), "application/pdf");
          }
      

      在不使用 ReportViewer 的情况下,我没有找到任何其他替代方法来在 MVC 中导出 SSRS 报告。

      【讨论】:

      • 为什么我使用
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-12
      • 1970-01-01
      • 1970-01-01
      • 2011-04-01
      相关资源
      最近更新 更多