title: C# File/Directory Permissions
body: <p>I am writing an application to manage user access to files. The short version of a very long story is that I have to use directory and file priveleges to do it. No document management system for our cheap CEO...</p>
  
  <p>Anyway... I have everything working except the case where the user can view which files are in the directory but not actually see the contents of the file. (There may be sensitive HR data in the files.)</p>
  
  <p>I tried FileSystemRights.ListDirectory, but that seems to (dispite MS documentation) set ReadData to true as well. I turn off ReadData (the ability to read the files) and I suddenly have no access to the directory again. The two appear linked.</p>
  
  <p>Any ideas for which permission(s) to set to achieve this?</p>
  
  <p>My current code is:</p>
  
  <pre><code>SetSecurity(pth, usr, FileSystemRights.ListDirectory, AccessControlType.Allow);
  
  ...
  
  public void SetSecurity(string dirName, string account,
      FileSystemRights rights, AccessControlType controlType)
  {
      // Get a FileSecurity object that represents the
      // current security settings.
      DirectorySecurity dSecurity = Directory.GetAccessControl(dirName);
  
      dSecurity.AddAccessRule(new FileSystemAccessRule(account, rights, controlType));
  
      // Set the new access settings.
      Directory.SetAccessControl(dirName, dSecurity);
  }
  </code></pre>
  
  <p>Thanks.</p>
  
  <p>--Jerry</p>