// Recursive private CaseIgnoringSortedSetType AttributeValuesMultiString(string attributeName, DirectoryEntry objectEntry, CaseIgnoringSortedSetType valuesCollection, bool recursive) { PropertyValueCollection ValueCollection = objectEntry.Properties[attributeName]; IEnumerator enumerator = ValueCollection.GetEnumerator(); while (enumerator.MoveNext()) { if (enumerator.Current != null) { if (!valuesCollection.Contains(enumerator.Current.ToString())) { valuesCollection.Add(enumerator.Current.ToString()); if (recursive) { AttributeValuesMultiString(attributeName, LdapPrefix + enumerator.Current.ToString(), valuesCollection, true); } } } } return(valuesCollection); }
private bool UserIsNetworkGroupMember(string userName, string groupName) { bool userIsNetworkGroupMember = false; try { // Get thje Group's Distinguished Name string groupDistinguishedName = DistinguishedNameFromCommonName(groupName); SearchResult userSearchResult = SearchResultCollectionFindOne("(&(SAMAccountName=" + userName + ")(ObjectClass=user))"); if (userSearchResult != null) { // Search returned a result CaseIgnoringSortedSetType userGroupCollection = NetworkGroupsForUser(userSearchResult.GetDirectoryEntry().Path, true); userIsNetworkGroupMember = userGroupCollection.Contains(groupDistinguishedName); } // Search returned a result } catch (Exception eek) { } return(userIsNetworkGroupMember); }