title: Dowload a pdf from a link with c#
body: <p>I have a windows service application that needs to download pdf files from different public web sites and save them locally to a folder on the server</p>
  
  <p>I tried to use System.Net.WebClient to perform the download like this</p>
  
  <pre><code> client = new WebClient();
   client.DownloadFile(new Uri(fileLink, UriKind.Absolute), destination);
  </code></pre>
  
  <p>destination is the full path and name to the folder where I need to save the file to. example: \server-name\downloads\file123.pdf</p>
  
  <p>fileLink is the url to the pdf file</p>
  
  <p>One of the links I am trying to save is:  <a href="https://www.wvmmis.com/WV%20Medicaid%20Provider%20SanctionedExclusion/WV%20Medicaid%20Exclusions%20-%20June%202016.pdf" rel="nofollow">https://www.wvmmis.com/WV%20Medicaid%20Provider%20SanctionedExclusion/WV%20Medicaid%20Exclusions%20-%20June%202016.pdf</a></p>
  
  <p>The code works but the file that is saved is corrupted and cannot be opened by Acrobat reader or any pdf reader.</p>
  
  <p>If you click the link above and do save as and save the page locally to a pdf, then you can open it fine. So the problem is not that the pdf is really corrupted, but WebClient is not saving it right.</p>
  
  <p>Is there any configuration I can do to the WebClient that causes it to save the file correctly, or is there another way to do it that does save it right ?</p>
  
  <p>Thank you </p>