Click here to Skip to main content
15,883,705 members
Articles / Programming Languages / C#
Article

Simple Active Directory Browser Dialog

Rate me:
Please Sign up or sign in to vote.
4.00/5 (16 votes)
25 Mar 20071 min read 79.7K   3.5K   47   6
Folder/File-like Browser Dialog for Active Directory Objects

Screenshot - DirectoryServicesBrowser.jpg

Introduction

Attached is an extremely simple DirectoryServicesBrowserDialog Form that can be added to any Active Directory application. It acts similar to a FileOpenDialog or FolderOpenDialog class. In addition to providing an interface for browsing for Active Directory objects, it also sets some properties that can be called after selecting an object such as the object's fully qualified path, the objectGUID, and the common name of the object.

Background

This Form uses a few of the methods from a previous article of mine: Howto: (Almost) Everything In Active Directory via C#. Of course, if I were to use this dialog in production I would extend it to do a lot more, but this should serve as a clean demonstration of how to use some of the methods presented in that article.

Using the code

There's nothing to it. Just instantiate the object and send in credentials (if necessary). When the application calls the _Load event the browser will enumerate the forest for the domains attached. To keep the application snappy, you must select a node to be able to expand it to see the object's children.

Opening the Dialog with the credentials of the Logged in User

C#
DirectoryServicesBrowserDialog DirectoryBrowser =
      new DirectoryServicesBrowserDialog(null, null);
DirectoryBrowser.ShowDialog();

Opening the Dialog with the credentials of a service account

C#
DirectoryServicesBrowserDialog DirectoryBrowser =
        new DirectoryServicesBrowserDialog
        ("ServiceUserName", "ServiceUserPassword");
DirectoryBrowser.ShowDialog();

History

  • Originally submitted on 25 March 2007

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


Written By
Software Developer
United States United States
I'm a professional .NET software developer and proud military veteran. I've been in the software business for 20+ years now and if there's one lesson I have learned over the years, its that in this industry you have to be prepared to be humbled from time to time and never stop learning!

Comments and Discussions

 
QuestionFind Domain Controllers on a domain computer without logging into the domain Pin
moonimpression22-Jan-15 10:17
moonimpression22-Jan-15 10:17 
GeneralMy vote of 2 Pin
Aecho Liu18-Sep-14 17:23
Aecho Liu18-Sep-14 17:23 
GeneralRe: My vote of 2 Pin
thund3rstruck18-Sep-14 18:11
thund3rstruck18-Sep-14 18:11 
Generalawsome! Pin
species217526-Nov-09 1:06
species217526-Nov-09 1:06 
GeneralBrilliant Pin
chrishulbert10-Mar-09 18:17
chrishulbert10-Mar-09 18:17 
GeneralI gotta tell ya... Pin
Shog925-Mar-07 16:01
sitebuilderShog925-Mar-07 16:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.