Active Directory TreeView / Select AD Container Dialog
This is a WinForms dialog window (I have a WPF version as well, if anyone wants that just let me know) that will show all containers and OUs in a specified domain and let the user select a container/OU. You can then retrieve the full distinguished name for the OU they selected by checking the SelectedContainerPath property after you have shown the dialog window.
UPDATED 10/11/2011
I've removed the old version of this control and replaced it with a new version which is actually a proper dialog window rather than a control and is a lot faster, better written, no longer requires you to provide the OU/container icons yourself, and is used more similarly to other standard .NET dialog windows
Here's a screenshot of the new version in action
There's an example project that shows how to use the dialog window within the attached solution, but here's a basic example anyway:
vb.net Code:
Dim SelectContainerDialog As New Cjwdev.ActiveDirectory.Dialogs.SelectAdContainerDialog
If SelectContainerDialog.ShowDialog() = Windows.Forms.DialogResult.OK Then
MessageBox.Show(SelectContainerDialog.SelectedContainerPath)
End If
SelectContainerDialog.Dispose()
That's all there is to it
If you don't want it to show the domain tree for the current user's domain, you can set the DomainName property to specify an alternate domain and the Username and Password properties to specify alternate credentials if required. Here's a better example showing this:
Vb.net Code:
Using SelectContainerDialog As New Cjwdev.ActiveDirectory.Dialogs.SelectAdContainerDialog
SelectContainerDialog.Title = "Please select a container"
SelectContainerDialog.DomainName = DomainBox.Text
SelectContainerDialog.Username = UsernameBox.Text
SelectContainerDialog.Password = PasswordBox.Text
If SelectContainerDialog.ShowDialog() = Windows.Forms.DialogResult.OK Then
MessageBox.Show(SelectContainerDialog.SelectedContainerPath)
End If
End Using