Abstractions.Windows.Security.ReplaceFileSecurity C# (CSharp) Method

ReplaceFileSecurity() public static method

public static ReplaceFileSecurity ( string File, IdentityReference Account, FileSystemRights Rights, AccessControlType ControlType, InheritanceFlags Inherit, PropagationFlags Propagation ) : System.Boolean
File string
Account System.Security.Principal.IdentityReference
Rights FileSystemRights
ControlType AccessControlType
Inherit InheritanceFlags
Propagation PropagationFlags
return System.Boolean
        public static Boolean ReplaceFileSecurity(string File, IdentityReference[] Account, FileSystemRights Rights, AccessControlType ControlType, InheritanceFlags Inherit, PropagationFlags Propagation)
        {
            FileInfo fInfo = new FileInfo(File);
            FileSecurity fSecurity = fInfo.GetAccessControl();

            try
            {
                fSecurity.SetAccessRuleProtection(true, false);
                foreach (IdentityReference account in Account)
                {
                    fSecurity.ResetAccessRule(new FileSystemAccessRule(account, Rights, Inherit, Propagation, ControlType));
                }
                fInfo.SetAccessControl(fSecurity);
            }
            catch (Exception ex)
            {
                LibraryLogging.Error("unable to ReplaceFileSecurity for {0} error {1}", File, ex.Message);
                return false;
            }

            return true;
        }

Same methods

Security::ReplaceFileSecurity ( string File, string Account, FileSystemRights Rights, AccessControlType ControlType, InheritanceFlags Inherit, PropagationFlags Propagation ) : System.Boolean