Solved

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

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

740 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