Programaticamente atribuir permissões de lista de controle de acesso (ACL) a 'esta pasta, subpastas e arquivos'
Eu tenho que atribuir permissão em uma pasta e é pasta filho e arquivos programaticamente usando o C # .NET. Eu estou fazendo isso como abaixo:
<code>var rootDic = @"C:\ROOT"; var identity = "NETWORK SERVICE"; //The name of a user account. try { var accessRule = new FileSystemAccessRule(identity, fileSystemRights: FileSystemRights.Modify, inheritanceFlags: InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, propagationFlags: PropagationFlags.InheritOnly, type: AccessControlType.Allow); var directoryInfo = new DirectoryInfo(rootDic); // Get a DirectorySecurity object that represents the current security settings. DirectorySecurity dSecurity = directoryInfo.GetAccessControl(); // Add the FileSystemAccessRule to the security settings. dSecurity.AddAccessRule(accessRule); // Set the new access settings. directoryInfo.SetAccessControl(dSecurity); } catch (Exception ex) { //... } </code>
Ele atribui permissão na minha pasta 'C: \ ROOT'. Mas atribui permissão apenas às subpastas e arquivos, mas não à pasta 'ROOT'.
P: Como posso definir oFileSystemAccessRule
instância para atribuir permissão para a pasta RAIZ, subpastas e arquivos?