Team LiB
Previous Section Next Section

Traversing Objects in Active Directory

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.

Code Example: Traversing Objects in Active Directory
Start example
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;
                  }
          }
}
End example

Team LiB
Previous Section Next Section