Click here to Skip to main content
15,849,907 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to perform Sync operation with network folder or shared folder. Before performing the sync, I want to check all the permissions with that folder. Actually there are 13 permissions in windows NTFS folder.
First I need to perform below tasks one by one.
List out all the 13 permissions of the windows share folder and store it in List<T>.
The NTFS 13 permissions list:
• Traverse folder / execute file
• List folder / read data
• Read attributes
• Read extended attributes
• Create files / Write data
• Create folders / append data
• Write attributes
• write extended attributes
• Delete subfolders and files
• Delete
• Read permissions
• Change permissions
• Take ownership
After that based on the permissions only I need to start the Sync.
I tried with below code but I got only 5 permissions “Write, Read, Full control, Create, Delete”

Any one please tell me possible solution for doing this functionality.

What I have tried:

C#
string path = @"C:\ExportFolder";
string NtAccountName = @"MyDomain\MyUserOrGroup";

DirectoryInfo di = new DirectoryInfo(path);
DirectorySecurity acl = di.GetAccessControl(AccessControlSections.All);
AuthorizationRuleCollection rules = acl.GetAccessRules(true, true, typeof(NTAccount));

//Go through the rules returned from the DirectorySecurity
foreach (AuthorizationRule rule in rules)
{
    //If we find one that matches the identity we are looking for
    if (rule.IdentityReference.Value.Equals(NtAccountName, StringComparison.CurrentCultureIgnoreCase))
    {
        var filesystemAccessRule = (FileSystemAccessRule)rule;

        //Cast to a FileSystemAccessRule to check for access rights
        if ((filesystemAccessRule.FileSystemRights & FileSystemRights.WriteData) > 0 && filesystemAccessRule.AccessControlType != AccessControlType.Deny)
        {
            Console.WriteLine(string.Format("{0} has write access to {1}", NtAccountName, path));
        }
        else
        {
            Console.WriteLine(string.Format("{0} does not have write access to {1}", NtAccountName, path));
        }
    }
}
Posted
Updated 24-Nov-20 23:19pm
v2
Comments
BillWoodruff 24-Nov-20 10:19am    
Do you get the same number of rules for folder on the desktop, or other locations ?
Gerry Schmitz 25-Nov-20 10:30am    
Just dump everything ... then start filtering. I don't think you know what you're retrieving.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900