Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Downloading a PDF File from a URL

Downloading a PDF File from a URL

Scheduled Pinned Locked Moved C#
csharphelpasp-netwcf
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    Vimalsoft Pty Ltd
    wrote on last edited by
    #1

    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) { try { // 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; } finally { this.con.Close(); } } The Error i get when its supposed to download the file is The remote server returned an error: (401) Unauthorized. Please help

    Vuyiswa Maseko, Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code. C#/VB.NET/ASP.NET/SQL7/2000/2005/2008 http://www.vimalsoft.com vuyiswa[at]vimalsoft.com

    OriginalGriffO 1 Reply Last reply
    0
    • V Vimalsoft Pty Ltd

      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) { try { // 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; } finally { this.con.Close(); } } The Error i get when its supposed to download the file is The remote server returned an error: (401) Unauthorized. Please help

      Vuyiswa Maseko, Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code. C#/VB.NET/ASP.NET/SQL7/2000/2005/2008 http://www.vimalsoft.com vuyiswa[at]vimalsoft.com

      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #2

      The error message is very clear and explicit: "The remote server returned an error: (401) Unauthorized." That means that you need to log your downloader in to the site in some way in order to get access to teh files. I'd suggest you talk to the site owners about the best way to do that!

      Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups