Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

C# NTFS Permisssions

Posted on 2008-06-25
2
Medium Priority
?
788 Views
Last Modified: 2013-12-16
I need a bit of advice on setting permissions on a created directory, i am new to c# and have searched the net but i am really one the wiser, basically i call the following method after the userFolder is created:



The permissions that i want to have on the userFolder is List Folder Contents and Read, i can get the first one with the above code but dont know how to set the Read permission.

I need to have two permission entries for the user that the folder is assigned to which are ReadAndExecute and Read.

Any advice will be greatly appreciated!

Cheers
CODE
  private void FolderPermissions(string rootDir, string userFolder)
    {
      DirectoryInfo dinfo = new DirectoryInfo(rootDir + userFolder);
      DirectorySecurity dSecurity = dinfo.GetAccessControl();
 
      FileSystemAccessRule rule = new FileSystemAccessRule(userName, FileSystemRights.ReadAndExecute,
        InheritanceFlags.ContainerInherit, PropagationFlags.None, AccessControlType.Allow);
 
      dSecurity.SetAccessRule(rule);
      dinfo.SetAccessControl(dSecurity);
    }

Open in new window

0
Comment
Question by:ajayq
2 Comments
 
LVL 6

Expert Comment

by:Bruce_1975
ID: 21866342
Change the line

FileSystemAccessRule rule = new FileSystemAccessRule(userName, FileSystemRights.ReadAndExecute,
        InheritanceFlags.ContainerInherit, PropagationFlags.None, AccessControlType.Allow);

to following.

Regards,
Bruce


FileSystemAccessRule rule = new FileSystemAccessRule(userName, FileSystemRights.ReadAndExecute & FileSystemRights.Read,
        InheritanceFlags.ContainerInherit, PropagationFlags.None, AccessControlType.Allow);

Open in new window

0
 

Accepted Solution

by:
ajayq earned 0 total points
ID: 21866666
FileSystemAccessRule rule = new FileSystemAccessRule(userName, FileSystemRights.ReadAndExecute & FileSystemRights.Read,
        InheritanceFlags.ContainerInherit, PropagationFlags.None, AccessControlType.Allow);

This does not quite word the Read permission overrids the ReadAndExecute.

On the ACL i need the List Folder Contents, Read allow checkboxes ticked and under the advanced button there is two permission entires needed Read&Execute and Read for the user of the folder.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

927 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