aagbo
asked on
Apply NTFS Permissions to folders and sub-folders
I am trying to have a folder with a username created with 2 subfolders. I need to have the folder grant a specific user read-only access to the folder while still retaining the inherited permissions. One of the subfolders need to grant the user Write access. So the structure will look like this:
c:\ftp (not listed in ACL)
c:\ftp\username (ReadOnly)
c:\ftp\username\ToUser (readonly)
c:\ftp\username\FromUser (write)
Now, I've grabbed code from other posts and got it almost working. The problem I have is the permissions are being applied correctly to the subfolders, but the user-named folder lists the user in the ACL, but they have no effective permissions.
Here is the code that calls the function:
Then here is the code for the function:
I can't figure out why my top username folder isn't getting the accesspermissions set on them.
c:\ftp (not listed in ACL)
c:\ftp\username (ReadOnly)
c:\ftp\username\ToUser (readonly)
c:\ftp\username\FromUser (write)
Now, I've grabbed code from other posts and got it almost working. The problem I have is the permissions are being applied correctly to the subfolders, but the user-named folder lists the user in the ACL, but they have no effective permissions.
Here is the code that calls the function:
AddDirectorySecurity((userDirectory), Me.AccountName.Text, FileSystemRights.ReadAndExecute, AccessControlType.Allow)
Then here is the code for the function:
Sub AddDirectorySecurity(ByVal FileName As String, ByVal Account As String, ByVal Rights As FileSystemRights, ByVal ControlType As AccessControlType)
' Get a DirectorySecurity object that represents the current security settings.
Dim dSecurity As DirectorySecurity = Directory.GetAccessControl(FileName)
' Add the FileSystemAccessRule to the security settings (**following is one line of code**).
dSecurity.AddAccessRule(New FileSystemAccessRule(Account, Rights, (InheritanceFlags.ContainerInherit + InheritanceFlags.ObjectInherit), PropagationFlags.InheritOnly, ControlType))
' Set the new access settings.
dSecurity.SetAccessRuleProtection(True, True)
Directory.SetAccessControl(FileName, dSecurity)
I can't figure out why my top username folder isn't getting the accesspermissions set on them.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Worked perfectly. Thank you.
ASKER