Results 1 to 40 of 124

Thread: Populate TreeView with Active Directory objects

Threaded View

  1. #1

    Thread Starter
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007

    Populate TreeView with Active Directory objects

    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: Code:
    1. Dim SelectContainerDialog As New Cjwdev.ActiveDirectory.Dialogs.SelectAdContainerDialog
    2. If SelectContainerDialog.ShowDialog() = Windows.Forms.DialogResult.OK Then
    3.       MessageBox.Show(SelectContainerDialog.SelectedContainerPath)
    4. End If
    5. 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: Code:
    1. Using SelectContainerDialog As New Cjwdev.ActiveDirectory.Dialogs.SelectAdContainerDialog
    2.             SelectContainerDialog.Title = "Please select a container"
    3.             SelectContainerDialog.DomainName = DomainBox.Text
    4.             SelectContainerDialog.Username = UsernameBox.Text
    5.             SelectContainerDialog.Password = PasswordBox.Text
    6.             If SelectContainerDialog.ShowDialog() = Windows.Forms.DialogResult.OK Then
    7.                 MessageBox.Show(SelectContainerDialog.SelectedContainerPath)
    8.             End If
    9. End Using
    Attached Files Attached Files
    Last edited by chris128; Nov 10th, 2011 at 04:25 PM. Reason: New version
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Click Here to Expand Forum to Full Width