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.
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)
{
//...
}
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?
You just need to remove the
PropagationFlags.InheritOnlyflag. By specifying that you are stating that the ACE should not apply to the the target folder. UsePropagationFlags.Noneinstead. You may find this MSDN article helpful.