public IEnumerable <Principal> Find(ADCriteria criteria = null, ADObjectType objectType = ADObjectType.User) { List <Principal> results = new List <Principal>(); ADCriteria query; //Get an 'entry' for the directory we want DirectoryEntry entry = new DirectoryEntry(String.Format("LDAP://{0}", _Name), _userid, _password); //Create a 'searcher' DirectorySearcher searcher = new DirectorySearcher(entry); if (criteria == null) { criteria = new NullCriteria(); } if (objectType == ADObjectType.User) { query = criteria.And(new BaseCriteria("objectClass", "user")); } else if (objectType == ADObjectType.Group) { query = criteria.And(new BaseCriteria("objectClass", "group")); } else { query = criteria; } searcher.Filter = query.ToString(); searcher.PropertiesToLoad.Clear(); searcher.PropertiesToLoad.Add("cn"); searcher.PageSize = 250; //For each search result... foreach (SearchResult result in searcher.FindAll()) { Principal item = GetPrincipal(result); if (item != null) { //Add a UserPrincipal object to the result list for this ID results.Add(item); } } return(results); }
public IEnumerable<Principal> Find(ADCriteria criteria=null, ADObjectType objectType = ADObjectType.User) { List<Principal> results = new List<Principal>(); ADCriteria query; //Get an 'entry' for the directory we want DirectoryEntry entry = new DirectoryEntry(String.Format("LDAP://{0}", _Name), _userid, _password); //Create a 'searcher' DirectorySearcher searcher = new DirectorySearcher(entry); if (criteria == null) { criteria = new NullCriteria(); } if (objectType== ADObjectType.User) { query=criteria.And(new BaseCriteria("objectClass","user")); } else if (objectType == ADObjectType.Group) { query=criteria.And(new BaseCriteria("objectClass","group")); } else { query=criteria; } searcher.Filter = query.ToString(); searcher.PropertiesToLoad.Clear(); searcher.PropertiesToLoad.Add("cn"); searcher.PageSize = 250; //For each search result... foreach (SearchResult result in searcher.FindAll()) { Principal item=GetPrincipal(result); if (item != null) { //Add a UserPrincipal object to the result list for this ID results.Add(item); } } return results; }