Using DirectorySearcher : Active Directory : Web Services C# Source Code


Custom Search

C# Source Code » Web Services » Active Directory »

 

Using DirectorySearcher








    
 

using System;
using System.Net;
using System.DirectoryServices;


public class MainClass {
    public static void Main() {
        using (DirectoryEntry de = new DirectoryEntry("LDAP://yourV/OU=yourV, DC=explorer, DC=local"))
        using (DirectorySearcher searcher = new DirectorySearcher()) {
            de.Username = @"explorer\yourName";
            de.Password = "password";
            searcher.SearchRoot = de;
            searcher.Filter = "(&(objectClass=user)(description=Auth*))";
            searcher.SearchScope = System.DirectoryServices.SearchScope.Subtree;
            searcher.PropertiesToLoad.Add("name");
            searcher.PropertiesToLoad.Add("description");
            searcher.PropertiesToLoad.Add("givenName");
            searcher.PropertiesToLoad.Add("wWWHomePage");
            searcher.Sort = new SortOption("givenName", SortDirection.Ascending);
            SearchResultCollection results = searcher.FindAll();
            foreach (SearchResult result in results) {
                ResultPropertyCollection props = result.Properties;
                foreach (string propName in props.PropertyNames) {
                    Console.Write(propName + ": ");
                    Console.WriteLine(props[propName][0]);
                }
            }
        }
    }
}

 
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Web Services
» Active Directory