DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Aniruddha has posted 40 posts at DZone. View Full User Profile

How To Check File Permissions In C#

  • submit to reddit
        Use following snippet to find a file's associated DACL (Discretionary Access control List)
ArrayList fileACL = new ArrayList();
FileSecurity fileSecurity = new FileSecurity(@"C:\Windows\system.ini", AccessControlSections.Access);

            AuthorizationRuleCollection arc = fileSecurity.GetAccessRules(true, true, typeof(NTAccount));
            foreach (FileSystemAccessRule rule in arc)
                fileACL.Add(rule.IdentityReference + ":" + rule.AccessControlType + " " + rule.FileSystemRights.ToString());