Solved

C# NTFS Permisssions

Posted on 2008-06-25
2
783 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

821 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