title: Accessing Password Protected Network Drives in Windows in C#?
body: <p>So in C# I am trying to access a file on a network, for example at "//applications/myapp/test.txt", as follows:</p>
  
  <pre><code>const string fileLocation = @"//applications/myapp/test.txt";
  using (StreamReader fin = new StreamReader(FileLocation))
  {
       while(!fin.EndOfStream()){
            //Do some cool stuff with file
       }
  }
  </code></pre>
  
  <p>However I get the following error:</p>
  
  <pre><code>System.IO.IOException : Logon failure: unknown user name or bad password.
  </code></pre>
  
  <p>I figure its because I need to supply some network credentials but I'm not sure how to get those to work in this situation. </p>
  
  <p>Does anyone know the best way (or any way) to gain access to these files that are on a a password protected location?</p>
  
  <p>Thanks in advance!!</p>