title: Getfiles() UnAuthorizedAccessAcception in WIN7
body: <p><strong>Problems</strong></p>
  
  <ol>
  <li>UnAuthorizedAccessException: When searching a directory recursively such as C:\<br>
    A "Access to the path 'c:\Documents and Settings\' is denied." Occurs even with UAC  Priveledges upgraded &amp; Administrator group access.<br></li>
  </ol>
  
  <p><strong>Attempted Methods</strong><br></p>
  
  <ol>
  <li>Try &amp; Catch: Using either one of these methods(Exception, UnAuthorizedAccessException, Blank Catch, continue)</li>
  </ol>
  
  <p><strong>Questions</strong><br></p>
  
  <ol>
  <li>How do you handle this kind of exception and continue running your program as normal? This needs to work both on non-admin and administrator accounts.</li>
  </ol>
  
  <p><strong>Example Code</strong><br></p>
  
  <pre><code>using System;
  using System.IO;
  
  namespace filecheck
  {
      class Program
      {
          static void Main(string[] args)
          {
              int i = 0;
              int html = 0;
              try
              {
                  string[] filePaths = Directory.GetFiles(@"c:\", "*.html", SearchOption.AllDirectories);
  
                  foreach (string files in filePaths)
                  {
                      if (Convert.ToBoolean(files.IndexOf("html")))
                      {
                          html++;
                      }
                      Console.WriteLine(files);
                      i++;
  
                  }
                  Console.Write("# Files found: {0} Html: {1)", i, html);
              }
              catch (UnauthorizedAccessException e)
              {
                  Console.WriteLine("The process failed: {0}", e.ToString());
              }
              catch (Exception e)
              {
                  Console.WriteLine("The process failed: {0}", e.ToString());
  
              }
  
          }
      }
  }
  </code></pre>