CMS-Team
asked on
Setting read/write/modify rights to everyone in a folder in C#
I'm copying a complete website into a specific location and I'm triying to give rights to everyone(LOCAL) to every folder in it because the user can download and make the server create files and folders, I'm using Win32_UserAccount and Win32_Account but for most users I'm getting the following error(Including aspnet which I think is the most important):
System.Security.Principal. IdentityNo tMappedExc eption: Some or all identity references could not be translated.
at System.Security.Principal. NTAccount. Translate( IdentityRe ferenceCol lection sourceAccounts, Type targetType, Boolean forceSuccess)
at System.Security.Principal. NTAccount. Translate( Type targetType)
at System.Security.AccessCont rol.Common ObjectSecu rity.Modif yAccess(Ac cessContro lModificat ion modification, AccessRule rule, Boolean& modified)
at System.Security.AccessCont rol.Common ObjectSecu rity.AddAc cessRule(A ccessRule rule)
at System.Security.AccessCont rol.FileSy stemSecuri ty.AddAcce ssRule(Fil eSystemAcc essRule rule)
at
Check out my code below for more information.
System.Security.Principal.
at System.Security.Principal.
at System.Security.Principal.
at System.Security.AccessCont
at System.Security.AccessCont
at System.Security.AccessCont
at
Check out my code below for more information.
SelectQuery sQuery = new SelectQuery("Win32_UserAccount", "Domain<>'"
+ System.Environment.UserDomainName.ToString() + "'");
ManagementObjectSearcher mSearcher = new ManagementObjectSearcher(sQuery);
foreach (ManagementObject mObject in mSearcher.Get())
{
DirectorySecurity myDirectorySecurity = folder.GetAccessControl();
string User = System.Environment.UserDomainName + "\\" + mObject["Name"].ToString();
myDirectorySecurity.AddAccessRule(new FileSystemAccessRule(User, FileSystemRights.CreateFiles, AccessControlType.Allow));
myDirectorySecurity.AddAccessRule(new FileSystemAccessRule(User, FileSystemRights.Modify, AccessControlType.Allow));
myDirectorySecurity.AddAccessRule(new FileSystemAccessRule(User, FileSystemRights.Traverse, AccessControlType.Allow));
myDirectorySecurity.AddAccessRule(new FileSystemAccessRule(User, FileSystemRights.ChangePermissions, AccessControlType.Allow));
//myDirectorySecurity.AddAccessRule(new FileSystemAccessRule(User, FileSystemRights.Modify, AccessControlType.Allow));
folder.SetAccessControl(myDirectorySecurity);
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.