Ste*_*ger 9 .net c# vb.net file-permissions
我得到一个UnautorizedAccessException运行此代码:
string[] fileList = Directory.GetFiles(strDir, strExt);
Run Code Online (Sandbox Code Playgroud)
发生在异常c:\users\username\appdata
如何,我可以检查我是否有访问权限(列出和读取文件)?
首先,我会手动检查权限,看看是什么阻止了你,什么不阻止.我使用这样的东西来检查权限(对于复制文件):
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
}
Run Code Online (Sandbox Code Playgroud)
此外,还有一些奇怪的情况,文件夹上的某个权限会更改文件的权限,无论其个人权限如何(将查看我是否可以找到它的内容).
| 归档时间: |
|
| 查看次数: |
38587 次 |
| 最近记录: |