2

So I have followed the code from this site(Exporting SSRS Report to PDF in MVC Action) and various others, but nothing seem to work. I want a link on a web page in mvc that will download a report as a pdf. The url works fine web I browse to it but I keep getting this error: "The remote server returned an error: (401) Unauthorized." in mvc. This is my code at the moment:

public ActionResult Download()
        {
            var url = "http://xxxx/ReportServer/Pages/ReportViewer.aspx?%2fxxx+xxx%2fxxx+Report&rs:Command=Render&CellNumber=";

            NetworkCredential nwc = new NetworkCredential("xxx", "xxx", "xxx");
            WebClient client = new WebClient();
            client.Credentials = nwc;
            client.UseDefaultCredentials = false;
            string reportURL = String.Format("{0}{1}{2}", url, Cellphone, "&rs:Format=PDF");
            return File(client.DownloadData(reportURL), "application/pdf");
        }

When I remove the "&rs:Format=PDF" part it authorizes, but then the app fails after that. Please Help.

Community
  • 1
  • 1
spmoolman
  • 403
  • 8
  • 20

0 Answers0