DirectoryServices Get Error 0x80005000 when using special symbol '/'

0

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)
        {


        }
directoryservices
asked on Stack Overflow Jul 4, 2013 by HateBear • edited Jul 5, 2013 by HateBear

1 Answer

0

Fixed In my case , Just repleace to group name with folling coding.

groupName = groupName.Replace("/", "\/");

answered on Stack Overflow Jul 5, 2013 by HateBear

User contributions licensed under CC BY-SA 3.0