velgames
velgames

Reputation: 35

C# Edit file system directory privileges from admin process

I need to allow edit files in directory to users. Directory and files in it was created with admin priviliges. So, when user try to resave files in it - exception. What I can do in this case? Or may be exist a way to create directory with specific rights? I am using C# .Net 4.0

Upvotes: 0

Views: 82

Answers (1)

Arheus
Arheus

Reputation: 192

Grand access for all users (with subfolders) like this:

DirectoryInfo dInfo;
DirectorySecurity dSecurity = dInfo.GetAccessControl();
dSecurity.AddAccessRule(new FileSystemAccessRule(new SecurityIdentifier(WellKnownSidType.WorldSid, null), FileSystemRights.FullControl, InheritanceFlags.ObjectInherit | InheritanceFlags.ContainerInherit, PropagationFlags.InheritOnly, AccessControlType.Allow));
dInfo.SetAccessControl(dSecurity);

Upvotes: 1

Related Questions