Click here to Skip to main content
15,905,148 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
It is easy to get the current user's credentials for any file or folder. But the problem is that to get a collection of permissions (Read, Read Attributes, Write, etc.) for any given user or group, and I can not find a solution. The files and folders is located in network share resource. Users and groups is AD based. It is wery easy to manage accounts with System.DirectoryServices. But permissions on file system objects is not in AD, and that problem.

I would be very grateful for help!
Posted

1 solution

C#
void ListDirAccessList()
       {
           // Get the ACL of the directory
           //
           System.IO.DirectoryInfo dirInfo = new System.IO.DirectoryInfo(@"C:\Test");
           DirectorySecurity dirSec = dirInfo.GetAccessControl();

           // Show the ACEs of the ACL
           //
           int i = 0;
           foreach (FileSystemAccessRule rule in dirSec.GetAccessRules(true, true, typeof(System.Security.Principal.NTAccount)))
           {
               Console.WriteLine("[{0}] - Rule {1} {2} access to {3}",
               i++,
               rule.AccessControlType == AccessControlType.Allow ? "grants" : "denies",
               rule.FileSystemRights,
               rule.IdentityReference.ToString());
           }
       }
 
Share this answer
 

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