Solved

find user permission

Posted on 2013-10-31
11
209 Views
Last Modified: 2014-01-28
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
0
Comment
Question by:Varshini S
11 Comments
 
LVL 39

Expert Comment

by:Kyle Abrahams
Comment Utility
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
 
LVL 15

Expert Comment

by:unknown_routine
Comment Utility
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
 

Author Comment

by:Varshini S
Comment Utility
ged325 - The sample code won't support for .net ramework 2.0 , Am I correct ?
0
 
LVL 39

Expert Comment

by:Kyle Abrahams
Comment Utility
Rubha it should work . . . did you try it?
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

Author Comment

by:Varshini S
Comment Utility
ged325 - I tried that but I am getting the error.

please see my attached the screen shot
ERROR.png
0
 
LVL 96

Expert Comment

by:Bob Learned
Comment Utility
You have a screen shot that shows the red squigglies, but not the error text...
0
 
LVL 39

Accepted Solution

by:
Kyle Abrahams earned 500 total points
Comment Utility
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
 

Author Comment

by:Varshini S
Comment Utility
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

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now