DirectoryEntry groupEntry = new DirectoryEntry("LDAP://CN=Sales,CN=Users,DC=contoso,DC=com");
List<string> list = new List<string>();
foreach(string dn in groupEntry.Properties["members"]) {
try {
if(DirectoryEntry.Exists("LDAP://"+dn)) {
list.Add(dn);
}
} catch(Exception e) {
list.Add(e.Message);
}
}
return list;
The list returned should be
CN=Sales Americas,CN=Users,DC=contoso,DC=com
CN=Sales EMEA,CN=Users,DC=contoso,DC=com
CN=Sales D/A/CH,CN=Users,DC=contoso,DC=com
CN=Sales SEA,CN=Users,DC=contoso,DC=com
but it is
CN=Sales Americas,CN=Users,DC=contoso,DC=com
CN=Sales EMEA,CN=Users,DC=contoso,DC=com
Unbekannter Fehler (0x80005000)
CN=Sales SEA,CN=Users,DC=contoso,DC=com
I think that the problem is the /
special character. How would I have to encode this character for it to work in DirectoryEntry.Exists
? Do you know other special characters that can be part of a CN name, which I have to encode?
The values in members attribute are already valid DN.
But when putting DN into LDAP path you still have to escape the "/", which don't need escape in DN but not in LDAP path.
You can simply replace any "/" with "\/" in DN.
User contributions licensed under CC BY-SA 3.0