在.NET中,检查当前用户可写目录 [英] In .NET, check that the current user may write to a directory
问题描述
在.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
}
这篇关于在.NET中,检查当前用户可写目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!