讀取文件夾的權限如何獲得一個目錄寫權限具有以下名稱格式HOST用戶\ UerName針對特定用戶
我都試過,但它不工作
DirectoryInfo di = new DirectoryInfo(path);
DirectorySecurity acl = di.GetAccessControl();
AuthorizationRuleCollection rules = acl.GetAccessRules(true, true, typeof(System.Security.Principal.NTAccount));
//Go through the rules returned from the DirectorySecurity
foreach (AuthorizationRule rule in rules)
{
//If we find one that matches the identity we are looking for
if (user_name == rule.IdentityReference.Value)) //(rule.IdentityReference.ToString().Contains(NtAccountName))
{
//Cast to a FileSystemAccessRule to check for access rights
if ((((FileSystemAccessRule)rule).FileSystemRights & FileSystemRights.WriteData) > 0)
{
up.write = true;
}
if ((((FileSystemAccessRule)rule).FileSystemRights & FileSystemRights.Read) > 0)
{
up.read = true;
}
if ((((FileSystemAccessRule)rule).FileSystemRights & FileSystemRights.ExecuteFile) > 0)
{
up.execute = true;
}
if ((((FileSystemAccessRule)rule).FileSystemRights & FileSystemRights.Delete) > 0)
{
up.delete = true;
}
}
}
請,不包括有關在問題的標題,除非它是沒有意義的使用的語言信息沒有它。標籤用於此目的。 –