Search code examples
findalladam

How to search Single user From LADP:


I have a method that will search particular User into ADAM.

 'set up the LDAP entry object
        objEntry = New DirectoryEntry("LDAP://" & m_strLDAPServer & ":" & m_strLDAPPort & "/" & m_strLDAPEntry)
is the default but it must be set explicitly so that the props array can be passed in
        objSearcher = New DirectorySearcher(objChild, "(objectClass=*)", strProps)
        objSearcher.SearchScope = SearchScope.Base

 objSearcher = New DirectorySearcher(objChild, "(objectClass=*)", strProps)
        objSearcher.SearchScope = SearchScope.Base
        'carry out the search
        Try
            objResult = objSearcher.FindOne()
        Catch
            objResult = Nothing
        End Try

I want to get Results from ADAM SQL: Like '%strUserName%', but I found only method FindOne() that only search the full string "strUserName", but it not performing the SQL Like Operation. Any Idea How can I search like SQL LIKE?


Solution

  • Its works fine:

    eobjEntry = New DirectoryEntry("LDAP://" & m_strLDAPServer & ":" & m_strLDAPPort & "/" & "cn=" & txtUserName & "," & m_strLDAPEntry)
        'set the user name and password, if necessary
    
        Dim search As New DirectorySearcher()
    

    'here search & txtUserName & works SQL Like Operation objSearcher = New DirectorySearcher(objEntry, "(cn=" & txtUserName & ")") objSearcher.SearchScope = SearchScope.Base And SearchScope.OneLevel Dim result As SearchResult = search.FindOne()