Solved

C# NTFS Permisssions

Posted on 2008-06-25
2
779 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 Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
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…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

706 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

18 Experts available now in Live!

Get 1:1 Help Now