When I try to add the ADUser to ADGroup , I get the error(0x80005000)
addUserToGroup("userA","CB HQ (P&D)"); <--Its work to add the user in group
addUserToGroup("userb","CB HQ (P/D)"); when the program access to --if (!dirEntry.Properties["member"].Contains(userPath))-- will throw the error(0x80005000)
static void addUserToGroup(String loginName, String groupName){
string groupPath = String.Format("{0}CN={1},OU={2},{3}", LDAPStr, groupName, OUStr, DCStr);
string userPath = getUserPathByLogin(loginName);
try
{
if (!String.IsNullOrEmpty(userPath))
{
DirectoryEntry dirEntry = new DirectoryEntry(groupPath, ADUserName, ADPassword);
if (!dirEntry.Properties["member"].Contains(userPath))
{
dirEntry.Properties["member"].Add(userPath);
dirEntry.CommitChanges();
}
}
}
catch (Exception ex)
{
}
Fixed In my case , Just repleace to group name with folling coding.
groupName = groupName.Replace("/", "\/");
User contributions licensed under CC BY-SA 3.0