111,089
社区成员




public static bool SetFolderACL(
String folderPath,
String userName,
FileSystemRights rights,
AccessControlType allowOrDeny,
InheritanceFlags inherits,
PropagationFlags propagateToChildren,
AccessControlModification addResetOrRemove)
{
bool ret = false;
try
{
var folder = new DirectoryInfo(folderPath);
var dSecurity = folder.GetAccessControl(AccessControlSections.All);
var accRule = new FileSystemAccessRule(userName, rights, inherits, propagateToChildren, allowOrDeny);
dSecurity.ModifyAccessRule(addResetOrRemove, accRule, out ret);
folder.SetAccessControl(dSecurity);
}
catch (Exception exp)
{
Trace.Write(Trace.LogType.Fault, "Set Folder ACL", folderPath + "\t" + exp.Message);
}
return ret;
}
public static bool ResetFolderModifiable(String direcotry, string userName)
{
return SetFolderACL(direcotry, userName,
FileSystemRights.CreateFiles | FileSystemRights.Read | FileSystemRights.Write,
AccessControlType.Allow,
InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit,
PropagationFlags.None,
AccessControlModification.Reset);
}
注意这两个参数
InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit,
PropagationFlags.None,
username可以用组名(everyone)或者当前用户名