知道我是否具有对目录的读写权限. [英] Knowing whether I have read\write access to a directory.

查看:60
本文介绍了知道我是否具有对目录的读写权限.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用.net 2.0在C#中构建Windows窗体应用程序.
我有一个与目录关联的DirectoryInfo实例.谁能告诉我我怎么知道:-
1.我的应用程序是否对目录具有读取权限.
2.我的应用程序是否对该目录具有写权限.
是否有任何方法\属性可用于执行此任务?如果是这样,请告诉我.
在此先谢谢您.

I am using .net 2.0 to build a windows form application in C#.
I have a DirectoryInfo instance associated with a directory. Can any one tell me how can I know:-
1. Whether my application read access to the directory.
2. Whether my application have write access to the directory.
Is there any method\Property available for doing this task? If so, let me know.
Thanks in advance.

推荐答案

根据此http://bytes.com/topic/c-sharp/answers/259010-reading-file-permissions [ ^ ].您可以通过Windows API和P/Invoke来执行此操作.

另请参见有用的相关小代码集: http://www.java2s .com/Tutorial/CSharp/0300__File-Directory-Stream/0240__File-Permission.htm [
There is no a managed way to acquire file/directory permissions (Access Control List), according to this http://bytes.com/topic/c-sharp/answers/259010-reading-file-permissions[^]. You can do this via Windows API and P/Invoke.

See also this, a useful set of related codelets: http://www.java2s.com/Tutorial/CSharp/0300__File-Directory-Stream/0240__File-Permission.htm[^].

Permission is not the only reason for inaccessible files.

However, do you really need to get into this sophisticated stuff? I have my own practical non-nonsense approach to this. I do access under try-catch block, catch access exception and process it the way I want. It is very practical, because it''s very hard to do all checks. This is exactly what structured exceptions are design for. As access to a new file system object does not happen often, there is no performance hit.

—SA


此问题已发布
This question was posted here[^] by someone else. Hope the answer helps you!


本文将为您提供帮助:
This article should help: http://bytes.com/topic/c-sharp/answers/537508-check-permissions-folder


这篇关于知道我是否具有对目录的读写权限.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆