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
Amitava_MukherjeeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

lazyberezovskyCommented:
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

0
Amitava_MukherjeeAuthor Commented:
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.
0
Shahan AyyubSenior Software EngineerCommented:
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
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Amitava_MukherjeeAuthor Commented:
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'
0
Steve BinkCommented:
Here is an article from a guy who went through the same process:

http://www.conarc.com/blog/2010/03/25/programmatically-getting-effective-directoryfile-permissions/

There is not a lot of material on this concept, and I'm inclined to say there is no built-in method of obtaining this information.  This means you have to parse the permissions yourself and recreate it.  While not impossible, that is an algorithm that will take time to get right.  Perhaps you can go back to your concept and re-examine if you *really* need effective permissions to do what you want.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Bob LearnedCommented:
I believe the resource that would help you is this nice article:

Programmatically Getting Effective Directory/File Permissions
http://www.conarc.com/blog/2010/03/25/programmatically-getting-effective-directoryfile-permissions/
0
Steve BinkCommented:
lol...nice..  :)
0
Bob LearnedCommented:
Sweet timing!!  Great minds, and all that!!
0
Amitava_MukherjeeAuthor Commented:
Thanks for the solution
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.