Solved

How to browse for OU folder structure from Active Directory to select an OU.

Posted on 2007-03-17
4
608 Views
Last Modified: 2013-11-26
I'm trying to create an application with VB.Net. I would like to retrieve the OU folder structure from my Active Directory and put this in a treeview. Then i need to select an OU and put the selected OU into a value that i need for the next action. It does not have to be a treeview, it could also be something like a browse button where i can browse to the OU i wanted.

Other suggestions to solve this are also welcome.

Roland
0
Comment
Question by:AACCosmos
  • 3
4 Comments
 
LVL 67

Accepted Solution

by:
sirbounty earned 500 total points
Comment Utility
You'll need to add a reference to directory services.
Here's some good links on it...
http://www.ondotnet.com/pub/a/dotnet/2003/07/28/activedir.html
http://www.codeproject.com/vb/net/LDAP_Using_VBnet.asp
0
 
LVL 1

Author Comment

by:AACCosmos
Comment Utility
When start with the given example at http://www.codeproject.com/vb/net/LDAP_Using_VBnet.asp, i get error message: Name '_LdapServerName' is not declared.

0
 
LVL 1

Author Comment

by:AACCosmos
Comment Utility
I also found this:

Imports System
Imports System.DirectoryServices

Class DirLister

    Shared Sub Main(ByVal args() As String)
   
    Dim enTry As DirectoryEnTry = New DirectoryEnTry("LDAP://mijndomein")
    Dim mySearcher As DirectorySearcher = New DirectorySearcher(enTry)
    mySearcher.Filter = ("(objectClass=computer)")
    Console.WriteLine("Overzicht van computers in de Active Directory")
    Console.WriteLine("============================================")
    Dim resEnt As SearchResult
    For Each resEnt In mySearcher.FindAll()
    Console.WriteLine(resEnt.GetDirectoryEnTry().Name.ToString())
    Next
    Console.WriteLine("=============== Einde Overzicht=============")
End Sub
End Class

And changed it into:

Imports System
Imports System.DirectoryServices
Public Class Form1

    Class DirLister

        Shared Sub Main(ByVal args() As String)

            Dim enTry As DirectoryEntry = New DirectoryEntry("LDAP://192.168.1.61")
            Dim mySearcher As DirectorySearcher = New DirectorySearcher(enTry)
            mySearcher.Filter = ("(objectClass=computer)")

            Dim resEnt As SearchResult
            For Each resEnt In mySearcher.FindAll()
                Form1.Text = (resEnt.GetDirectoryEntry().Name.ToString())
            Next

        End Sub
    End Class

But this isn't showing reslults and also didn't show some error's.
0
 
LVL 1

Author Comment

by:AACCosmos
Comment Utility
I got the OU structure into a treeview with this code:

Imports System.DirectoryServices
Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim enTry As DirectoryEntry = New DirectoryEntry("LDAP://myserver/DC=mydomain, DC=local")
        Dim mySearcher As DirectorySearcher = New DirectorySearcher(enTry)
        mySearcher.Filter = "(objectClass=OrganizationalUnit)"

        Dim resEnt As SearchResult
        For Each resEnt In mySearcher.FindAll()
            TreeView1.Nodes.Add(resEnt.GetDirectoryEntry().Name)
        Next
    End Sub

    Private Sub TreeView1_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect

    End Sub
End Class

Now i need to get a real tree structure, i got at the moment only a list with the OU, not into a treeview structure.

Roland
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now