find user permission

Using the c# code , I want  verify  the login  user has following permissions

create folder
delete folder
create file
modify file
delete file
copy file

I am using .net frame work 2.0
Varshini SAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
Kyle AbrahamsConnect With a Mentor Senior .Net DeveloperCommented:
Make sure you have using System.Linq;

Also, if you were to hit ctrl + period over rule or authorizationRules it would prompt you to add the object.

Did you add the entire function?


private static FileSystemAccessRule[] GetAccessRulesArray(string userName, string path) {  
  // get all access rules for the path - this works for a directory path as well as a file path    AuthorizationRuleCollection authorizationRules = (new FileInfo(path)).GetAccessControl().GetAccessRules(true, true, typeof(SecurityIdentifier));     

// get the user's sids    
string[] sids = GetSecurityIdentifierArray(userName);     

// get the access rules filtered by the user's sids    
return (from rule in authorizationRules.Cast<FileSystemAccessRule>()            where sids.Contains(rule.IdentityReference.Value)            select rule).ToArray();
}

Open in new window

0
 
Kyle AbrahamsSenior .Net DeveloperCommented:
You need to determine the effective permissions on the parent folder.

Here's a blog that explains how to do that in detail . . . if you have any questions about it please feel free to post so I can explain further:
http://www.conarc.com/blog/2010/03/25/programmatically-getting-effective-directoryfile-permissions/
0
 
unknown_routineCommented:
You need to use FileSystemAccessRule Class.

Take a look at the example in this page:

http://msdn.microsoft.com/en-us/library/system.security.accesscontrol.filesystemaccessrule(v=vs.80).aspx
0
What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

 
Varshini SAuthor Commented:
ged325 - The sample code won't support for .net ramework 2.0 , Am I correct ?
0
 
Kyle AbrahamsSenior .Net DeveloperCommented:
Rubha it should work . . . did you try it?
0
 
Varshini SAuthor Commented:
ged325 - I tried that but I am getting the error.

please see my attached the screen shot
ERROR.png
0
 
Bob LearnedCommented:
You have a screen shot that shows the red squigglies, but not the error text...
0
 
Varshini SAuthor Commented:
ged325- Thank You ,The function is working fine but when I execute this application in a workgroup computer it is throwing error since it is not in the domain. How do I change the same below method to work in work group computers ?

private static string[] GetSecurityIdentifierArray(string userName)
        {
            // connect to the domain
            PrincipalContext pc = new PrincipalContext(ContextType.Domain);

            // search for the domain user
            UserPrincipal user = new UserPrincipal(p
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.