The following example demonstrates how to access child objects of an Active Directory object. This is useful in situations where you have a parent organizational unit (OU) and you wish to iterate through the members of the OU.
using System;
using System.DirectoryServices;
namespace Chapter12
{
public class DirectoryBinding
{
public DirectoryBinding()
{
DirectoryEntry MyDirectoryObject = new DirectoryEntry();
MyDirectoryObject.Path = "LDAP://HMSRevenge/rootDSE";
MyDirectoryObject.Username = @"redmond\gregmcb";
MyDirectoryObject.Password = @"MyPassword";
//Gets the child objects and returns
//them into a collection
DirectoryEntries MyChildObjects =
MyDirectoryObject.Children;
}
}
}