Solved

C# NTFS Permisssions

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

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…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

734 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