Link to home
Start Free TrialLog in
Avatar of Amitava_Mukherjee
Amitava_MukherjeeFlag for India

asked on

Get Effective Permission using .NET

I want to get the effective permissions of an user on a directory or file by using .NET.
How to get it in C#?
Thank You
Avatar of lazyberezovsky
lazyberezovsky
Flag of Belarus image

For directory use Directory.GetAccessControl
string identityReference = @"Domain\UserName";
string path = "file.txt";

FileSecurity fileSecurity = File.GetAccessControl(path);
foreach(FileSystemAccessRule rule in fileSecurity.GetAccessRules(true, true, typeof(System.Security.Principal.NTAccount)))
{                 
    if(rule.IdentityReference.Value == identityReference)
    {
        // use rule.FileSystemRights and rule.AccessControlType                                      
    }                
}

Open in new window

Avatar of Amitava_Mukherjee

ASKER

This function works if I explicitely give rights to a particular user on the file/folder, but not the effective rights.
Please provide some C# code so that I can get the Effective Permission.
Sorry for the delayed response.
Avatar of Shahan Ayyub
I could not get what do you mean about 'EFFECTIVE PERMISSION', but as i understood, check the following web address:


http://stackoverflow.com/questions/130617/how-do-you-check-for-permissions-to-write-to-a-directory-or-file
If I right click a folder and then select Security -> Advanced, I get an 'EFFECTIVE PERMISSION' Tab. Then if I select the user if shows some permissions - I want to get that 'EFFECTIVE PERMISSION'
ASKER CERTIFIED SOLUTION
Avatar of Steve Bink
Steve Bink
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
lol...nice..  :)
Sweet timing!!  Great minds, and all that!!
Thanks for the solution