471,317 Members | 1,597 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,317 software developers and data experts.

Directory access

Hi,

What is the *proper* way to determine if I have write-access to a given
directory?

Thanks!
BT
Dec 26 '05 #1
2 4981
Bit Twiddler wrote:
Hi,

What is the proper way to determine if I have write-access to a given
directory?


Get first a DirectoryInfo object using:
DirectoryInfo di = new DirectoryInfo(@"c:\MyDir");

then, call di.GetAccessControl() (or the overload).

FB

--
------------------------------------------------------------------------
Get LLBLGen Pro, productive O/R mapping for .NET: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
Dec 27 '05 #2
DirectoryInfo.GetAccessControl() returns a DirectorySecurity object:

DirectoryInfo di = new DirectoryInfo(@"c:\MyDir");
DirectorySecurity ds = di.GetAccessControl();

Now I can call ds.AccessRightType, but I don't understand why this returns a
Type, instead of a mask representing the FileSystemRights enumeration.

If I could get those flags I could just check for
FileSystemRights.CreateFiles, etc.

Any pointers would be appreciated!

Thanks,
BT
"Frans Bouma [C# MVP]" <pe******************@xs4all.nl> wrote in message
news:xn***************@news.microsoft.com...
Bit Twiddler wrote:
Hi,

What is the proper way to determine if I have write-access to a given
directory?


Get first a DirectoryInfo object using:
DirectoryInfo di = new DirectoryInfo(@"c:\MyDir");

then, call di.GetAccessControl() (or the overload).

FB

--
------------------------------------------------------------------------
Get LLBLGen Pro, productive O/R mapping for .NET: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------

Dec 27 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Tom Youngquist | last post: by
2 posts views Thread by Annette Massie | last post: by
1 post views Thread by Len Svitenko | last post: by
2 posts views Thread by Hari | last post: by
2 posts views Thread by web02 | last post: by
2 posts views Thread by mark babli | last post: by
reply views Thread by eholz1 | last post: by
1 post views Thread by jyohere | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.