title: Remove all directory permissions & set new permissions using C#
body: <p>I want to remove previously set directory permissions to a folder &amp; set new permissions as per requirement.</p>
  
  <p>I have referred this link
  <a href="https://stackoverflow.com/questions/1445388/remove-all-directory-permissions">Remove All Directory Permissions</a></p>
  
  <p>but once i removed all permission it never allows me to set new rules.</p>
  
  <p>my code</p>
  
  <pre><code> DirectoryInfo myDirectoryInfo = new DirectoryInfo("D:\\Shared\\Testing");
                  DirectorySecurity myDirectorySecurity = myDirectoryInfo.GetAccessControl();
                  string User = System.Environment.UserDomainName + "\\" + Convert.ToString(dt_UserDetails.Rows[i]["AD_NAME"]);
  
                  AuthorizationRuleCollection rules = myDirectorySecurity.GetAccessRules(true, true, typeof(System.Security.Principal.NTAccount));
  
                  myDirectorySecurity.SetAccessRuleProtection(true, false);
  
                  if (Convert.ToInt16(dt_UserDetails.Rows[i]["ACCESS_CONTROL_TYPE"]) == 1)
                  {
                      new FileSystemAccessRule(User, FileSystemRights.ChangePermissions, AccessControlType.Allow);
  
                  }
                  else if (Convert.ToInt16(dt_UserDetails.Rows[i]["ACCESS_CONTROL_TYPE"]) == 0)
                  {
                      new FileSystemAccessRule(User, FileSystemRights.ChangePermissions, AccessControlType.Deny);                    
                  }
  
                  myDirectoryInfo.SetAccessControl(myDirectorySecurity);
  </code></pre>
  
  <p>Is there any solution for this?</p>