Simple Active Directory Browser Dialog





4.00/5 (15 votes)
Mar 25, 2007
1 min read

80783

3532
Folder/File-like Browser Dialog for Active Directory Objects
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
DirectoryServicesBrowserDialog DirectoryBrowser =
new DirectoryServicesBrowserDialog(null, null);
DirectoryBrowser.ShowDialog();
Opening the Dialog with the credentials of a service account
DirectoryServicesBrowserDialog DirectoryBrowser =
new DirectoryServicesBrowserDialog
("ServiceUserName", "ServiceUserPassword");
DirectoryBrowser.ShowDialog();
History
- Originally submitted on 25 March 2007