I am trying to set ntfs permissions for a user folder such that the user has Read and Execute permissions for This Folder Only but has Full Control for All Subfolders and Files.
I am using this code, which is not doing what I need:
public void AddDirectorySecurity(string dirName, string userName)
{
DirectoryInfo dInfo = new DirectoryInfo(dirName);
DirectorySecurity dSecurity = dInfo.GetAccessControl();
dSecurity.AddAccessRule(new FileSystemAccessRule(userName,
FileSystemRights.ReadAndExecute, InheritanceFlags.ObjectInherit,
PropagationFlags.InheritOnly, AccessControlType.Allow));
dInfo.SetAccessControl(dSecurity);
dSecurity.AddAccessRule(new FileSystemAccessRule(userName,
FileSystemRights.FullControl, InheritanceFlags.None,
PropagationFlags.None, AccessControlType.Allow));
dInfo.SetAccessControl(dSecurity);
}
Can someone please offer some advice on what I need to change to get this working correctly?