Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exporting SSRS Report to PDF in MVC Action

Yes , I want to Export SSRS Report to the PDF and Return it from my action, I do not have any Report Viewer.Please Suggest me how can i achieve this. so far i have done this

    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();
    }

Above code throws an exception

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

My Questions are
1) Am i going in right direction?
2) Is There any Better Alternative to achieve this ?

like image 302
d.Siva Avatar asked Jul 24 '13 12:07

d.Siva


People also ask

How do I remove PDF option from export options in SSRS report?

Disable the PDF export option - add the visible attribute with value false . Enable the PDF export option - remove the visible attribute.


2 Answers

I Corrected the Above Code and now its Working

    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");
    }

i do not found any other alternative than this to export SSRS Report in MVC without using ReportViewer.

like image 55
d.Siva Avatar answered Sep 30 '22 18:09

d.Siva


try not specify the domain like this:

NetworkCredential nwc = new NetworkCredential("username", "password");
like image 43
apolo90 Avatar answered Sep 30 '22 17:09

apolo90