c# View folder permissions

188 Views Asked by At

I can search folder permissions using cacls.exe with command prompt and output them to a text file but I need to display the folder permissions within the C# program so that i can use them in strings etc.

1

There are 1 best solutions below

0
enginne On
DirectorySecurity dSecurity = Directory.GetAccessControl(@"d:\myfolder");
foreach (FileSystemAccessRule rule in dSecurity.GetAccessRules(true, true, typeof(NTAccount)))
{
    if (rule.FileSystemRights == FileSystemRights.Read)
    {
        Console.WriteLine("Account:{0}", rule.IdentityReference.Value);
    }
}