Solved

C# NTFS Permisssions

Posted on 2008-06-25
2
785 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
[X]
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
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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

626 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