0

I'm looking for the way to get list of the emails and groups of emails from the active directory. The list will be used to populate autocomplete textbox, the same as in Outlook. Have any of you done something like that in the past using Asp.Net MVC?

Whistler
  • 1,897
  • 4
  • 29
  • 50

1 Answers1

2

I made this in a project some time ago and here are few steps I think you need to take:

  1. Create a directory entry for your domain
  2. Create a directory searcher and initialize it with a filter
  3. Create a search collection searching with previous filter
  4. Iterate your search collection
  5. Get your properties for current iteration
  6. Get your email from property collection

Code example:

  DirectoryEntry dir = new DirectoryEntry("LDAP://" + YourDomain, LoginUsername, LoginPassword);
  DirectorySearcher search = new DirectorySearcher(dir);
  search.Filter = "(&(objectClass=user)(objectCategory=person))";
  SearchResultCollection searchResultCollection = search.FindAll();



if (searchResultCollection != null)
{
   for (int i = 0; i < searchResultCollection.Count; i++)
   { 
       SearchResult crt= searchResultCollection[i];
       PropertyCollection properties= crt.GetDirectoryEntry().Properties;

       // get email from properties["email"].Value
   }
}

Some useful links: first , second , third

Community
  • 1
  • 1
Cosmin
  • 2,184
  • 21
  • 38