Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

find user permission

Posted on 2013-10-31
11
217 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 40

Expert Comment

by:Kyle Abrahams
ID: 39614408
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
ID: 39614472
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
ID: 39615251
ged325 - The sample code won't support for .net ramework 2.0 , Am I correct ?
0
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
LVL 40

Expert Comment

by:Kyle Abrahams
ID: 39616750
Rubha it should work . . . did you try it?
0
 

Author Comment

by:Varshini S
ID: 39617651
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
ID: 39641467
You have a screen shot that shows the red squigglies, but not the error text...
0
 
LVL 40

Accepted Solution

by:
Kyle Abrahams earned 500 total points
ID: 39641725
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
ID: 39648817
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

828 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