在.NET中,有一个简单的方法来检查当前用户是否有权访问创建一个目录中的文件?东西等同于C ++ _access功能,将是理想的。
我不想用试错(创建一个虚拟文件,然后将其删除):除了表面上的hackish的,其他软件在监控有问题的目录下降的文件
我不希望使用System.DirectoryServices中:看ACL的,解决组成员,以及如何从不同的组成员的权限进行交互似乎很容易出错,太辛苦。必须有一个是的 - 或 - 不仅如此功能的地方,不是吗?
在此先感谢!
作为奖金,如果将工作网络共享为好,这会是很酷的。
解决方案 的FileIOPermission writePermission =新的FileIOPermission(FileIOPermissionAccess.Write,文件名);
如果(SecurityManager.IsGranted(writePermission)){
//写在这里
} 其他 {
//一些错误信息
}
In .NET, is there a simple way to check whether the current user has access to create a file in a directory? Something equivalent to the C++ _access function, would be ideal.
I don't want to use trial and error (create a dummy file and then delete it): apart from seeming hackish, other software is monitoring the directory in question for dropped files.
I don't want to use System.DirectoryServices: looking at ACL's, resolving group memberships and how permissions from different group memberships interact seems error prone and too hard. There must be a yeah-or-nay function somewhere, no?
Thanks in advance!
[edit] as a bonus, if it would work for a network share as well, that'd be cool.
解决方案FileIOPermission writePermission = new FileIOPermission(FileIOPermissionAccess.Write, filename);
if (SecurityManager.IsGranted(writePermission)){
//write here
} else {
//some error message
}
相关推荐
最新文章