connect LDAP using vb.net

richardblare

New member
Joined
Aug 13, 2007
Messages
1
Programming Experience
Beginner
Hi,
I need your help.I'm new to ldap. I want to create vb.net program to connect to ldap and retrieve some users from ldap by matching with value from text boxes and display the result. Thank you.
 
Ok so first off make sure that you add a reference to System.DirectoryServices for your project.

Then check out this code

Assumes "Imports System.DirectoryServices" is at the top.

VB.NET:
    Private Sub SearchLDAP()
        Dim objRoot As DirectoryEntry = New DirectoryEntry("LDAP://directory.gmu.edu/ou=people,o=gmu.edu")
        objRoot.AuthenticationType = AuthenticationTypes.None
        Dim objSearch As New DirectorySearcher(objRoot, "sn=Kahrl")
        objSearch.SearchScope = SearchScope.Subtree

        Dim objResults As SearchResultCollection = objSearch.FindAll

        For Each objResult As SearchResult In objResults
            MsgBox("E-Mail Address   : " & objResult.GetDirectoryEntry().Properties("mail").Value.ToString & Environment.NewLine & _
                   "Business Category: " & objResult.GetDirectoryEntry().Properties("businessCategory").Value.ToString)
        Next
    End Sub

This is a simple example. It can be a bit more elaborate of a search if needed.
 
Back
Top