Thursday, August 6, 2009

Set "everyone" Permission to Folder using C# in Asp.Net

Here is the simple C# code to set "everyone" permissions to the folder .

string redirectionFolder = @"D:\test\subtest\";

FileSystemAccessRule everyOne = new FileSystemAccessRule("Everyone", FileSystemRights.FullControl,AccessControlType.Allow);
DirectorySecurity dirSecurity = new DirectorySecurity(redirectionFolder, AccessControlSections.Group);
dirSecurity.AddAccessRule(everyOne);
Directory.SetAccessControl(redirectionFolder, dirSecurity);

Note:
If you get the error "Attempted to perform an unauthorized operation"

add the tag (<identity impersonate="true"/>) in your web.config file.

5 comments:

Chris said...

Thanks for this - it worked a charm!

Sathya said...

Ya It worked fine thanks for your post man

Sathya said...

If we set the identity impersonate it asking the username and password. what we want to give in that place???

Anonymous said...

Thanks! I searched everywhere for this.

digital signature Adobe Acrobat said...

I think that this would make a great template for my website. I have been looking for something like this. Thanks !