C#如何判断某个文件夹是否为共享,访问权限为只读

如题...
2024-12-23 08:30:57
推荐回答(1个)
回答1:

List ret = new List();

DirectorySecurity dirSec = Directory.GetAccessControl(@"c:\test", AccessControlSections.All);
AuthorizationRuleCollection rules = dirSec.GetAccessRules(true, true, typeof(System.Security.Principal.NTAccount));
foreach (FileSystemAccessRule rule in rules)
{
ret.Add(rule.FileSystemRights);
}

ret里面就是各个帐号对该目录的访问权限,你在里面判断一下就知道了,格式是这样的:
ReadData | WriteData | AppendData | ReadExtendedAttributes | WriteExtendedAttributes | ExecuteFile | DeleteSubdirectoriesAndFiles | ReadAttributes | WriteAttributes | Delete | ReadPermissions | ChangePermissions | TakeOwnership | Synchronize