Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2007-03-17
4
Medium Priority
?
641 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 67

Accepted Solution

by:
sirbounty earned 1500 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

What’s Wrong with Your Cloud Strategy ?

Even as many CIOs are embracing a cloud-first strategy, the reality is that moving to the cloud is a lengthy process and the end-state is likely to be a blend of multiple clouds—public and private. Learn why multicloud solutions matter in this webinar by Nimble Storage.

Question has a verified solution.

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

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

636 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