A basic Windows control library for selecting objects in your Active Directory.
I've been involved in several Active Directory projects and frequently have had the need for a "picker" utility to select objects in the AD hierarchy. I decided to roll my own and encapsulate it in a Windows control library.
Add the control to the list of Windows Forms controls in Visual Studio .NET, then drag the control onto a Windows Form. The control will automatically obtain your Active Directory root path and begin building a hierachal tree of the objects it finds.
private void AddTreeNodes(TreeNode node)
Cursor.Current = Cursors.WaitCursor;
adh = new ADHelper();
IDictionaryEnumerator enumerator = adh.Children.GetEnumerator();
TreeNode childNode = new TreeNode((string)enumerator.Key);
childNode.Tag = enumerator.Value; node.Nodes.Add(childNode);
childNode.ImageIndex = 3; }
Cursor.Current = Cursors.Default;
AddTreeNodes() takes only one parameter, the parent
TreeNode object. It then proceeds to add every child object it finds. Similar to Microsoft's ADSI Edit tool, the control displays a plus sign to indicate if a node has one or more child nodes.
Returning the ADsPath
Each time a node is selected in the hierarchy, the
ADsPath public property is updated to reflect the fully-qualified path to the object (i.e. LDAP://OU=DEV,OU=US,DC=CORPORATE,DC=MYDOMAIN,DC=COM).
public void GetChildEntries(string adspath)
if (adspath.Length > 0)
entry = new DirectoryEntry(adspath);
entry = new DirectoryEntry();
foreach (DirectoryEntry childEntry in entry.Children)
private void treeView1_AfterSelect(object sender,
_adspath = (string)e.Node.Tag;
The control has been tested on Windows 2000/XP/2003. It should work for Windows 9x/NT with the Microsoft Active Directory Client Extensions installed.
- Version 1.0 - 04.22.2004 - First release version.
- Version 1.1 - 04.28.2004 - Added image support for object types.
I live in southeastern Pennsylvania, USA with my lovely wife and two beautiful daughters. Life is good. My hobbies are motorcycles, motorcycles, and motorcycles.
I run a riders group called Twisties Motorcycle Club. If you're are a rider in the tri-state area, look us up! http://twistiesmc.com/