How to give permissions for folders in C#?
02:59 23 May 2011

I need to give the folder "Temporary ASP.NET Files" write permission using C#. My code:

DirectoryInfo d1 = new DirectoryInfo(Path.Combine(RuntimeEnvironment.GetRuntimeDirectory(), "Temporary ASP.NET Files"));
DirectorySecurity md1 = d1.GetAccessControl();


string user_1 = fa.TextGuestDomain + "\\" + fa.TextGuestUser;
md1.AddAccessRule(new FileSystemAccessRule(user_1, FileSystemRights.FullControl,InheritanceFlags.ObjectInherit,PropagationFlags.InheritOnly, AccessControlType.Allow));

d1.SetAccessControl(md1);

This checks the "Special permissions" box instead of the "Write" box in the folder security properties. Even when I attempt to turn on "Full control" or "Read" access instead of "Write", I get "Special permissions" turned on.

c# .net security permissions file-permissions