Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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 ?

    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.

How come I don't get a 401 by using an <iframe tag, the report displays correctly? But, when I use your code I get the 401? I'm using the user/pass that the datasource uses. Do I need to create new user/pass or use impersonation? – JoshYates1980 Mar 21, 2016 at 14:28

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.