且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

检查文件/文件夹访问权限

更新时间:2022-04-02 21:32:22

首先,我会手动检查权限,看看哪些会阻止您,哪些不会.我正在使用这样的东西来检查权限(复制文件):

First of all, I would manually check the permissions and see what blocks you and what doesn't. I am using something like this to check for permissions (for copy file):

AuthorizationRuleCollection acl = fileSecurity.GetAccessRules(true, true,typeof(System.Security.Principal.SecurityIdentifier));
bool denyEdit = false;
for (int x = 0; x < acl.Count; x++)
{
    FileSystemAccessRule currentRule = (FileSystemAccessRule)acl[x];
    AccessControlType accessType = currentRule.AccessControlType;
    //Copy file cannot be executed for "List Folder/Read Data" and "Read extended attributes" denied permission
    if (accessType == AccessControlType.Deny && (currentRule.FileSystemRights & FileSystemRights.ListDirectory) == FileSystemRights.ListDirectory)
    {
        //we have deny copy - we can't copy the file
        denyEdit = true;
        break;
    }
... more checks 
}

此外,还有一些奇怪的情况,文件夹上的某个权限会更改文件的权限,而不管它们的个***限如何(我会看看我是否能找到它).

Also, there are some strange cases where a certain right on the folder changes the right for the files regardless of their individual permissions (will see if I can find what it is).