Esempio n. 1
0
        public static bool HasWritePermisssion(this DirectoryInfoBase dirInfo)
        {
            try
            {
                var currentUserSecurityIdsArray = GetCurrentUserSecurityIdentifierArray();

                var directorySecurity = dirInfo.GetAccessControl();

                foreach (AuthorizationRule rule in directorySecurity.GetAccessRules(true, true, typeof(SecurityIdentifier)))
                {
                    if (currentUserSecurityIdsArray.Contains(rule.IdentityReference.Value))
                    {
                        FileSystemAccessRule rights = ((FileSystemAccessRule)rule);
                        if (rights.AccessControlType == AccessControlType.Allow)
                        {
                            if (rights.FileSystemRights == (rights.FileSystemRights | FileSystemRights.Modify))
                            {
                                return(true);
                            }
                        }
                    }
                }
                return(false);
            }
            catch
            {
                return(false);
            }
        }