I have used the code below to allow Everyone access to a folder:
System.Security.AccessControl.DirectorySecurity sec =
System.IO.Directory.GetAccessControl(directory, AccessControlSections.All);
FileSystemAccessRule accRule = new FileSystemAccessRule("Everyone",
FileSystemRights.Modify,
AccessControlType.Allow);
sec.AddAccessRule(accRule); // setACL
sec.ResetAccessRule(accRule);
Now, the Everyone user is added to the folder, but not with any rights assigned. All the read, write, execute etc. checkboxes are not checked.
The below code checks for the folder existence, if not created, creates one. And then sets every user- permission of that folder with full permission (read & write).
use
FileSystemRights.FullControl
instead ofFileSystemRights.Modify
if you want to allow all actions (ACL).First thing I want to tell you is how I found this solution. This is probably more important than the answer because file permissions are hard to get correct.
First thing I did was set the permissions I wanted using the Windows dialogs and checkboxes. I added a rule for "Everyone" and ticked all boxes except "Full Control".
Then I wrote this C# code to tell me exactly what parameters I need to duplicate the Windows settings:
This gave me this line of output:
So the solution is simple (yet hard to get right if you don't know what to look for!):
This will make the checkboxes on the Windows security dialog match what you have already set for your test directory.