0

I want to prevent user from moving/renaming/deleting folders but navigating inside the folder to see its sub folders and files; Also, the code can create sub folders/files inside the folder after setting these access rights. For files, i want also to prevent user to update/move/rename/delete but the app can do this. I played with the DirectorySecurity but i can't produce the desired results.

var directoryInfo = new DirectoryInfo(path);
            var directorySecurity = directoryInfo.GetAccessControl();

            var windowsIdentity = System.Security.Principal.WindowsIdentity.GetCurrent();
            if (windowsIdentity != null)
            {
                var userName = windowsIdentity.Name;
                directorySecurity.AddAccessRule(new FileSystemAccessRule(userName,
                    FileSystemRights.FullControl, AccessControlType.Deny));
                directorySecurity.AddAccessRule(new FileSystemAccessRule(userName,
                    FileSystemRights.Read | FileSystemRights.ListDirectory | FileSystemRights.CreateDirectories | FileSystemRights.CreateFiles , AccessControlType.Allow));
                directoryInfo.SetAccessControl(directorySecurity);
            }
yo2011
  • 971
  • 2
  • 12
  • 38
  • have look at this SO answer http://stackoverflow.com/a/5398398/1298308 and use SecurityIdentifier to set the correct access level to you directories – Aminul Dec 15 '15 at 11:20
  • Thanks for your help but it doesn't work as i want to prevent any user to delete/rename/move folder but he or she can navigate/create sub folders and files. – yo2011 Dec 15 '15 at 11:51
  • Hi, any help or comment – yo2011 Dec 15 '15 at 12:34

0 Answers0