asp.net-mvc – 在MVC Action中将SSRS报告导出为PDF

是的,我想将SSRS报告导出到PDF并将其从我的操作中返回,我没有任何Report Viewer.请告诉我如何实现这一点.到目前为止我做到了这一点

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)有没有更好的替代方案来实现这一目标?

解决方法

我纠正了上面的代码,现在它的工作

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报告.

dawei

【声明】:淮南站长网内容转载自互联网,其相关言论仅代表作者个人观点绝非权威,不代表本站立场。如您发现内容存在版权问题,请提交相关链接至邮箱:bqsm@foxmail.com,我们将及时予以处理。