public List <LDAPSearchResult> Search(ADProperties property, String propertyValue) { List <LDAPSearchResult> lstSearchResults = new List <LDAPSearchResult>(); try { DirectorySearcher search = new DirectorySearcher(entry); SearchResultCollection resultCollection; LoadProperties(ref search); search.Filter = "(" + property + "=*" + propertyValue + "*)"; resultCollection = search.FindAll(); if (resultCollection != null) { foreach (SearchResult result in resultCollection) { LDAPSearchResult objSearchResult = new LDAPSearchResult(); MapToObject(result, ref objSearchResult); lstSearchResults.Add(objSearchResult); } } } catch (Exception ex) { throw new Exception(ex.Message.ToString()); } return(lstSearchResults); }
public int CompareTo(object obj) { if (obj is LDAPSearchResult) { LDAPSearchResult u2 = (LDAPSearchResult)obj; return(_displayName.CompareTo(u2.displayName)); } else { throw new ArgumentException("Object is not a User."); } }
/// <summary> /// Maps the active directory results with the LDAPSearchResult object /// </summary> /// <param name="result"></param> /// <param name="objUser"></param> private void MapToObject(SearchResult result, ref LDAPSearchResult objSearchResult) { try { if (result.Properties["title"].Count > 0) { objSearchResult.Title = result.Properties["title"][0].ToString(); } if (result.Properties["distinguishedName"].Count > 0) { objSearchResult.distinguishedName = result.Properties["distinguishedName"][0].ToString(); } if (result.Properties["displayName"].Count > 0) { objSearchResult.displayName = result.Properties["displayname"][0].ToString(); } if (result.Properties["telephoneNumber"].Count > 0) { objSearchResult.telephoneNumber = result.Properties["telephoneNumber"][0].ToString(); } if (result.Properties["samAccountName"].Count > 0) { objSearchResult.samAccountName = result.Properties["samAccountName"][0].ToString(); } if (result.Properties["manager"].Count > 0) { objSearchResult.manager = FindOneByProperty(ADProperties.distinguishedName, result.Properties["manager"][0].ToString()); } if (result.Properties["department"].Count > 0) { objSearchResult.department = result.Properties["department"][0].ToString(); } if (result.Properties["givenName"].Count > 0) { objSearchResult.FirstName = result.Properties["givenName"][0].ToString(); } if (result.Properties["sn"].Count > 0) { objSearchResult.LastName = result.Properties["sn"][0].ToString(); } } catch (Exception ex) { throw new Exception(ex.Message.ToString()); } }
/// <summary> /// Cleans up ad search by property and maps to user defined object /// </summary> /// <param name="property"></param> /// <param name="propertyValue"></param> /// <returns></returns> private LDAPSearchResult FindOneByProperty(ADProperties property, String propertyValue) { LDAPSearchResult objSearchResult = new LDAPSearchResult(); try { SearchResult result = FindOne(property, propertyValue); if (result != null) { MapToObject(result, ref objSearchResult); } } catch (Exception ex) { throw new Exception(ex.Message.ToString()); } return(objSearchResult); }
/// <summary> /// Cleans up ad search by property and maps to user defined object /// </summary> /// <param name="property"></param> /// <param name="propertyValue"></param> /// <returns></returns> private LDAPSearchResult FindOneByProperty(ADProperties property, String propertyValue) { LDAPSearchResult objSearchResult = new LDAPSearchResult(); try { SearchResult result = FindOne(property, propertyValue); if (result != null) { MapToObject(result, ref objSearchResult); } } catch (Exception ex) { throw new Exception(ex.Message.ToString()); } return objSearchResult; }
/// <summary> /// Maps the active directory results with the LDAPSearchResult object /// </summary> /// <param name="result"></param> /// <param name="objUser"></param> private void MapToObject(SearchResult result, ref LDAPSearchResult objSearchResult) { try { if (result.Properties["title"].Count > 0) objSearchResult.Title = result.Properties["title"][0].ToString(); if (result.Properties["distinguishedName"].Count > 0) objSearchResult.distinguishedName = result.Properties["distinguishedName"][0].ToString(); if (result.Properties["displayName"].Count > 0) objSearchResult.displayName = result.Properties["displayname"][0].ToString(); if (result.Properties["telephoneNumber"].Count > 0) objSearchResult.telephoneNumber = result.Properties["telephoneNumber"][0].ToString(); if (result.Properties["samAccountName"].Count > 0) objSearchResult.samAccountName = result.Properties["samAccountName"][0].ToString(); if (result.Properties["manager"].Count > 0) objSearchResult.manager = FindOneByProperty(ADProperties.distinguishedName, result.Properties["manager"][0].ToString()); if (result.Properties["department"].Count > 0) objSearchResult.department = result.Properties["department"][0].ToString(); if (result.Properties["givenName"].Count > 0) objSearchResult.FirstName = result.Properties["givenName"][0].ToString(); if (result.Properties["sn"].Count > 0) objSearchResult.LastName = result.Properties["sn"][0].ToString(); } catch (Exception ex) { throw new Exception(ex.Message.ToString()); } }
public List<LDAPSearchResult> Search(ADProperties property, String propertyValue) { List<LDAPSearchResult> lstSearchResults = new List<LDAPSearchResult>(); try { DirectorySearcher search = new DirectorySearcher(entry); SearchResultCollection resultCollection; LoadProperties(ref search); search.Filter = "(" + property + "=*" + propertyValue + "*)"; resultCollection = search.FindAll(); if (resultCollection != null) { foreach (SearchResult result in resultCollection) { LDAPSearchResult objSearchResult = new LDAPSearchResult(); MapToObject(result, ref objSearchResult); lstSearchResults.Add(objSearchResult); } } } catch (Exception ex) { throw new Exception(ex.Message.ToString()); } return lstSearchResults; }