Solved

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

Posted on 2007-03-17
4
610 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
ID: 18740649
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
ID: 18741014
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
ID: 18741164
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
ID: 18744279
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VB.Net How to Exit Sub - Exit Form??? 5 51
Syntax Error 2 47
C# Single Form 8 28
Not seen Link button 5 17
Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

895 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

13 Experts available now in Live!

Get 1:1 Help Now