From: (e-mail address removed) (Steven Cheng[MSFT])
Organization: Microsoft
Date: Thu, 20 Dec 2007 06:20:07 GMT
Subject: RE: Determining user rights to a folder
Hi Ramon,
As for directory/file security, in .NET 2.0, there does provide built-in
classes for us to query or view the NTFS DACL of file/directory.
#ACL Technology Overview
http://msdn2.microsoft.com/en-us/library/ms229742(VS.80).aspx
Here are some article and test code that query the ACL list of a certain
file:
#Working with Access Control List in .NET 2.0
http://csharpfeeds.com/post.aspx?id=1460
private void button2_Click(object sender, EventArgs e)
{
string path = @"e:\temp\temp.txt";
FileSecurity fs = File.GetAccessControl(path,
AccessControlSections.All);
AuthorizationRuleCollection rules= fs.GetAccessRules(true,
true, typeof(NTAccount));
string msg = null;
foreach (FileSystemAccessRule rule in rules)
{
msg += "\r\n" + rule.IdentityReference.Value + "|" +
rule.AccessControlType.ToString() + ": " + rule.FileSystemRights.ToString();
}
MessageBox.Show(msg);
}
<<<<<<<<<<<
You can also modify them(add new entry or remove existing one) as long as
you have permission.
However, if you want to know whether a given account has the permission, I
think you still need to do further programming to compare the account with
those quried security identifiers. Maybe you can use ADSI or other queries
to get all the groups of a certain user and compare with the ACL list.
Hope this helps.
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#noti f
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
From: =?Utf-8?B?UmFtb24gR2VuZQ==?= <
[email protected]>
Subject: Determining user rights to a folder
Date: Wed, 19 Dec 2007 13:06:01 -0800
What's the best way in .Net (C#) to verify if an specific user has write
access to a folder?
Any code snippet is appreciated.
Thanks a lot,
Ramon