Active Directory access
-
Hi, I have a small windows application that connects to the local directory and retrieves the list of users. Then, it is possible to display the data of the user by clicking on a button. I use
LDAP://DomainName
to connect and things "seem" to be working fine. I manage to get the different data of the user I select (name, country, address, email, phone etc...) however I am having a problem with the "memberof" property. For some users, I am able to retrieve the list of groups he belongs to but for other users the property returns an empty collection. I am using the following piece of code:SearchResultCollection src = ds.FindAll(); SearchResult sr = src[0]; // I am filtering per username so only one match possible ResultPropertyValueCollection memberOf = sr.Properties["memberOf"]; // this sometimes returns zero items ResultPropertyValueCollection givenName = sr.Properties["givenName"]; ResultPropertyValueCollection lastName = sr.Properties["sn"]; ResultPropertyValueCollection email = sr.Properties["mail"]; ResultPropertyValueCollection address = sr.Properties["homePostalAddress"]; ResultPropertyValueCollection zip = sr.Properties["postalCode"]; ResultPropertyValueCollection country = sr.Properties["co"]; ResultPropertyValueCollection title = sr.Properties["title"]; ResultPropertyValueCollection city = sr.Properties["l"]; ResultPropertyValueCollection state = sr.Properties["st"]; ResultPropertyValueCollection phone = sr.Properties["telephoneNumber"]; ResultPropertyValueCollection otherPhone = sr.Properties["otherTelephone"]; ResultPropertyValueCollection fax = sr.Properties["facsimileTelephoneNumber"];
Then I filter the memberof collection like this:foreach (object role in memberOf) { string[] roleItems = role.ToString().Split(','); foreach (string temp in roleItems) { int i = temp.IndexOf("CN="); if (i >= 0) // found string { listGroups.Items.Add(temp.Substring(3)); } } }
This will give me the group name. I have tried displaying the whole "role" string without parsing, I thought maybe my parsing was not complete, but I didn't get anything either. I am new in Active Directory stuff and I have no idea if there is another way to do things. Any help would be greatly appreciated. Talal"Progra