title: WebClient DownloadFile method downloads damaged PDF files
body: <p>In my Windows application I am using WebClient DownloadFile method to download several PDF files from a server on local network.</p>
  
  <p>Each file is a report that gets generated when its URL is called. Reports are of different sizes and take different periods of time to get generated.</p>
  
  <p>My code loops through a list of URLs (about 400), and for each URL it calls DownloadFile method, and the corresponding report is generated and downloaded to local machine. URLs are definitely correct.</p>
  
  <p>The problem is that almost each time the application is run, some of downloaded files are damaged, only 7KBs are downloaded (I think it’s for meta data), and Acrobat Reader gives me a message when I try to open the file:
  “…it’s either not a supported file type or because the file has been damaged…”</p>
  
  <p>It’s not always the same files that get damaged, and when I re-run the application, those files often succeed, and some others might fail… it seems to be random and I can’t find out the criteria.</p>
  
  <p>Note 1: I don’t want a file to start download until its precedence is completely downloaded, that’s why I am not using the asynchronous method.
  Note 2: All files are Oracle reports and get generated by querying a database.
  Note 3: No EXCEPTION is thrown in case of damaged files.</p>
  
  <p>Here is my code :</p>
  
  <pre><code>using ( WebClient client  = new WebClient() )
  {
      for(int i=0; i&lt; URL_List.Length; i++)
      {
          try
          {
          client.DownloadFile( URL_List[i] , myLocalPath+fileName+".pdf" );
          }
          catch(Exception x)
          {
           // write exception message to error log...
          }
      }
  }
  </code></pre>
  
  <p>Thanks in advance. </p>