Click here to Skip to main content
6,595,854 members and growing! (21,999 online)
Email Password   helpLost your password?
Desktop Development » Selection Controls » General     Intermediate

Active Directory object picker control

By Marc Merritt

A Windows control for selecting objects in Active Directory.
C#, .NET, Win2K, WinXP, Win2003, Visual Studio, Dev
Posted:25 Apr 2004
Updated:16 May 2004
Views:112,733
Bookmarked:51 times
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
19 votes for this article.
Popularity: 5.59 Rating: 4.38 out of 5
1 vote, 5.3%
1

2
1 vote, 5.3%
3
2 votes, 10.5%
4
15 votes, 78.9%
5

Picker control test app

Introduction

A basic Windows control library for selecting objects in your Active Directory.

Background

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.

Sample Usage

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;
    treeView1.BeginUpdate();
    adh = new ADHelper();
    adh.GetChildEntries((string)node.Tag);
    IDictionaryEnumerator enumerator = adh.Children.GetEnumerator();

    // append children

    while (enumerator.MoveNext())
    {
        TreeNode childNode = new TreeNode((string)enumerator.Key);
        childNode.Tag = enumerator.Value; // ADsPath

        node.Nodes.Add(childNode);


        // specific object types

        if (!alExceptions.Contains(node.Text))
            childNode.ImageIndex =
                SetImageIndex(enumerator.Key.ToString().Substring(0,2));
        else
            childNode.ImageIndex = 3; // computer image

    }
    treeView1.EndUpdate();
    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);
    else
        entry = new DirectoryEntry();

    foreach (DirectoryEntry childEntry in entry.Children)
    {
        _htChildren.Add(childEntry.Name, childEntry.Path);
    }
}
private void treeView1_AfterSelect(object sender, 
      System.Windows.Forms.TreeViewEventArgs e)
{
    _adspath = (string)e.Node.Tag;
}

Compatibility

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.

History

  • Version 1.0 - 04.22.2004 - First release version.
  • Version 1.1 - 04.28.2004 - Added image support for object types.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Marc Merritt


Member
Doing my own consulting gig these days. It's so fun to work in your pajamas and act professional.

I live in southeastern Pennsylvania, USA with my lovely wife and two beautiful daughters. Life is good.
Occupation: Web Developer
Location: United States United States

Other popular Selection Controls articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 25 of 43 (Total in Forum: 43) (Refresh)FirstPrevNext
GeneralThe doubled child items [modified] Pinmemberpsychic8622:23 28 Jul '08  
GeneralThank you very much Pinmemberlucastar19:42 17 Jan '08  
GeneralRe: Thank you very much PinmemberMarc Merritt4:05 24 Jan '08  
GeneralRe: Thank you very much Pinmemberlucastar7:31 5 Feb '08  
GeneralThanks Pinmemberhkdl20009:46 27 Jun '07  
GeneralRe: Thanks PinmemberMarc Merritt17:10 28 Jun '07  
GeneralOUs are doubled Pinmemberandrei_teodorescu17:05 8 Jul '06  
GeneralRe: OUs are doubled Pinmembersebaj5:21 24 Feb '07  
GeneralNames ordered AD Pinmembertysonx5:17 6 Jun '06  
GeneralRe: Names ordered AD PinmemberMarc Merritt3:07 12 Jun '06  
QuestionHow can i get the selected object? Pinmemberrbmrf8:29 9 Mar '06  
AnswerRe: How can i get the selected object? PinmemberMarc Merritt8:48 9 Mar '06  
AnswerRe: How can i get the selected object? PinmemberData-Base4:53 17 Jul '08  
GeneralSorted Output? PinmemberVBDelinquent4:41 19 Dec '05  
GeneralRe: Sorted Output? PinmemberMarc Merritt8:00 22 Dec '05  
GeneralHelp Using in VS2005 Pinmemberastocks17:50 19 Oct '05  
GeneralRe: Help Using in VS2005 PinmemberMarc Merritt2:27 20 Oct '05  
GeneralRe: Help Using in VS2005 Pinmemberastocks10:48 20 Oct '05  
GeneralRe: Help Using in VS2005 PinmemberMarc Merritt12:40 20 Oct '05  
GeneralRe: Help Using in VS2005 Pinmemberastocks15:17 21 Oct '05  
QuestionSpecified domain does not exist Pinmembergiles papworth0:58 6 Sep '05  
AnswerRe: Specified domain does not exist PinmemberMarc Merritt4:48 12 Sep '05  
GeneralRe: Specified domain does not exist PinmemberDave Midgley5:41 5 Oct '05  
GeneralRe: Specified domain does not exist PinmemberMarc Merritt13:01 20 Oct '05  
GeneralRe: Specified domain does not exist PinmemberStefan de Groot9:02 17 Apr '07  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 16 May 2004
Editor: Nishant Sivakumar
Copyright 2004 by Marc Merritt
Everything else Copyright © CodeProject, 1999-2009
Web18 | Advertise on the Code Project