title: C# Test if user has write access to a folder
body: <p>I need to test if a user can write to a folder before actually attempting to do so. </p>
  
  <p>I've implemented the following method (in C# 2.0) that attempts to retrieve the security permissions for the folder using <a href="http://msdn.microsoft.com/en-us/library/c1f66bc2%28VS.80%29.aspx" rel="noreferrer">Directory.GetAccessControl()</a> method.</p>
  
  <pre><code>private bool hasWriteAccessToFolder(string folderPath)
  {
      try
      {
          // Attempt to get a list of security permissions from the folder. 
          // This will raise an exception if the path is read only or do not have access to view the permissions. 
          System.Security.AccessControl.DirectorySecurity ds = Directory.GetAccessControl(folderPath);
          return true;
      }
      catch (UnauthorizedAccessException)
      {
          return false;
      }
  }
  </code></pre>
  
  <p>When I was googling how to test for write access nothing like this came up and it appeared very complicated to actually test permissions in Windows. I am concerned that I am over-simplifying things and that this method is not robust,  although it does seem to work.</p>
  
  <p>Will my method to test if the current user has write access work correctly?</p>