Downloading a PDF File from a URL

Posted by Vuyiswamb under ASP.NET on 4/16/2015 | Points: 10 | Views : 1661 | Status : [Member] [MVP] [Administrator] | Replies : 0
Good Day All

i have a Reporting Service URL that i dynamically pass the Parameters on a Querystrng and if i take that URL and post it on a BRowser it downloads the PDF file. so i want to do this in C# , this code runs in a WCF service

public void GetAccountEmailStatement(string AccountNumber, string EmailAddress)

string remoteUri = "http://myserver/ReportServer/Pages/ReportViewer.aspx?%2fE-Billing%2fISU_PDF_GEN_1&rs:Command=Render&Contract_Account_Number=" + AccountNumber + "&Post_Date=26/02/15&rs:Format=PDF";
string fileName = HttpContext.Current.Server.MapPath("/Temp/" + AccountNumber + ".pdf");
WebClient webClient = new WebClient();
webClient.DownloadFile(remoteUri, fileName); //Error hapeens on this line

catch (SqlException ex)
throw ex;

The Error i get when its supposed to download the file is

[COLOR="#FF0000"]The remote server returned an error: (401) Unauthorized.[/COLOR]

Please help

Thank you for posting at Dotnetfunda


(No response found.)

Login to post response