title: Read permission on file denied
body: <p>I have a problem with reading a bunch of files using the following C# code in my VS2008 project</p>
  
  <pre><code>public void FindFiles()
  {
      //Root
      targetPath = Directory.GetDirectoryRoot(Directory.GetCurrentDirectory()) + "WriteToCSVFolder";
  }
  
  public void ReadFiles()
  {
      fileNameList_Original = Directory.GetFiles(targetPath);
  
      string defaultFileName = "file_";
      int counter = 0;
  
      foreach (string fileName in Directory.GetFiles(targetPath))
      {
          fullFileText_Original[counter] = File.ReadAllText(targetPath);
          //fileNameList_Original[counter]
          counter++;
      }
  
      counter = 0;
  }
  </code></pre>
  
  <p>Now please consider im just fast ticking this so I haven't bothered doing optimizations or anything yet. Just noticed that when I do a read action with the files NOT open and UAC (user account control) disabled on W7 64bit , and also not sharing it over network dropbox or anything else. It's just some ABC BLA FOO files I just made and wanted to test, they are in the correct directory marked targetpath in my system folder and the program is being run from the correct drive.</p>
  
  <p>Is it just something stupid in the code or?</p>
  
  <p>And oh yeah , the application was marked as full trust.</p>
  
  <p>Any ideas?</p>
  
  <p>EDIT:</p>
  
  <p>With the new idea implemented from the comment section below:</p>
  
  <p>Changed the code from</p>
  
  <pre><code>public void ReadFiles()
  {
      fileNameList_Original = Directory.GetFiles(targetPath);
  
      string defaultFileName = "file_";
      int counter = 0;
  
      foreach (string fileName in Directory.GetFiles(targetPath))
      {
          fullFileText_Original[counter] = File.ReadAllText(targetPath);
          //fileNameList_Original[counter]
          counter++;
      }
  
      counter = 0;
  }
  </code></pre>
  
  <p>TO</p>
  
  <pre><code>public void ReadFiles()
  {
      //Store all files names in a string array in one go
      fileNameList_Original = Directory.GetFiles(targetPath);
  
      string defaultFileName = "file_";
      int counter = 0;
  
      foreach (string fileName in Directory.GetFiles(targetPath))
      {
          //removed the storing file names, was redundant
          //added the suggested idea to the proper array
          fullFileText_Original[counter] = File.ReadAllText(fileName);
          //fileNameList_Original[counter]
          counter++;
      }
  
      counter = 0;
  }
  </code></pre>
  
  <p>Gives me nullreference exception on File, not sure what my conclusion should be from this error. Admitting that I am pretty tired atm , probably going to realize exactly what it was on the way home :)</p>
  
  <p>FINAL EDIT:</p>
  
  <p>See answers my own post.</p>