Solved

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

Posted on 2007-03-17
4
611 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Latency in .net app using DB in .net 21 65
VB 2005 Tooltips on Form Load Event 15 29
How to join on ID, with prefix? 15 58
get column names from table in vb.net 8 28
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

770 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