LDAP Query in VB.NET

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • maxamis4
    Recognized Expert Contributor
    • Jan 2007
    • 295

    LDAP Query in VB.NET

    Below is a code I am trying to write to retrieve information from LDAP using VB.NET. I am very versed in VB but .NET seems so foreign. If anyone can provide links and resources on how to use VB.NET with LDAP it would be greatly appreicated.


    Code:
            Private Sub btn_Search_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_Search.Click
    
            Dim UserID As String
            Dim RootDSE As New DirectoryServices.DirectoryEntry("LDAP://RootDSE")
            Dim DomainDN As String = RootDSE.Properties("DefaultNamingContext").Value
            Dim ADEntry As New DirectoryServices.DirectoryEntry("LDAP://" & DomainDN)
    
    
            Dim objSearch As New System.DirectoryServices.DirectorySearcher(ADEntry)
            'Dim ADSearchResult As System.DirectoryServices.SearchResult
            Dim oResults As DirectoryServices.SearchResultCollection
            Dim oResult As DirectoryServices.SearchResult
            Dim RetArray As New Hashtable
            Dim myresults As String
    
            UserID = "Gomez"
            objSearch.PropertiesToLoad.Add("uid")
            objSearch.PropertiesToLoad.Add("givenname")
            objSearch.PropertiesToLoad.Add("cn")
            objSearch.Filter = ("(samAccountName=*" & UserID & "*)")
            oResults = objSearch.FindAll
    
            For Each oResult In oResults
    
                myresults = oResult.GetDirectoryEntry.Properties("givenname").Value
    
                MsgBox(myresults)
    
            Next
    
        End Sub
  • maxamis4
    Recognized Expert Contributor
    • Jan 2007
    • 295

    #2
    Its working now. Please ignore.

    Comment

    Working...