title: Using WebClient to access local files
body: <p>I develop a C# application that needs to access many different content source both through HTTP, FTP and sometimes local files also (file://).</p>
  
  <p>I wanted to have a uniform way that I access these files through different protocols, so I had choosen WebClient to do this.</p>
  
  <p>It works well for all the different protocols as documented on MSDN (FTP, HTTP, local files, and so on), but then something goes wrong... after a couple successfull requests I just cannot access any files using URI for local files (file://c:\some_dir\somefile.ext). </p>
  
  <p>I have already checked the URI is correct, If I enter it in a browser it opens the file easily. I have recognized one really interesting thing - It also works well in the beginning for local files. If I try to load contents of a local file using WebClient, right at the start it all works well.</p>
  
  <p>My program looks like this:</p>
  
  <ol>
  <li>Main thread starting</li>
  <li>Some initialization on main thread</li>
  <li>Multiple threads downloading stuff from different sources</li>
  <li>Wait for all threads to finish</li>
  <li>Single thread processing dowloaded stuff</li>
  </ol>
  
  <p>As I've described before if I put my WebClient.DownloadData(url) invocation in the first step, it works fine, but when I try to access the COMPLETELY same URI in any of the threads of the third step, it fails to get any local files with URI starting with "file://".</p>
  
  <p>I use a very simple code to download/get local files:</p>
  
  <pre><code>WebClient wc = new WebClient();
  data = wc.DownloadData(url);
  </code></pre>
  
  <p>I wonder what could go wrong... Maybe I set something in the previous steps or in a concurrent thread that prevents me to access local files? In previous steps I do dowload content from FTP servers and through HTTP, maybe that causes the problem? I can easily access any local file if I try at the beginning of the main thread. When accessing FTP content I set credentials also. Maybe this is what effects my later requests?</p>