Continuing from my last post, the same can be achieved using SetAccessRuleProtection as shown below:
using System;
using System.Collections.Generic;
using System.Text;
using System.Security.AccessControl;
using System.IO;
using System.Security.Principal;
namespace AceInheritRemove
{
class Program
{
static void Main(string[] args)
{
// Get the object and its SecDescp
DirectoryInfo dir = new DirectoryInfo("e:\\kgk\\test");
DirectorySecurity sec = dir.GetAccessControl(AccessControlSections.All);
sec.SetAccessRuleProtection(true, false);
// Create a child folder with the explicit permissions only...
DirectoryInfo info2 = new DirectoryInfo("e:\\kgk\\Test\\Child");
info2.Create(sec);
dir.SetAccessControl(sec);
}
}
}