I have to assign permission on a folder and it's child folder and files programmatically using C#.NET. I'm doing this as below:
var rootDic = @"C:\ROOT";
var identity = "NETWORK SERVICE"; //The name of a user account.
var accessRule = new FileSystemAccessRule(identity,
inheritanceFlags: InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit,
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.
// Set the new access settings.
catch (Exception ex)
It does assign permission on my 'C:\ROOT' folder. But it assign permission to the Subfolders and Files only but not the 'ROOT' folder.
Q: How can I define the
FileSystemAccessRule instance to assign permission to the ROOT folder, Subfolders and files?