Directory Searcher Filter

I have a class that's getting the information I want but running too long

I THINK I need a filter on my Searcher.FindAll()

I want to look for a particular "user" based on thier login name


The FUnction is called with the following function and the "incomingUsername" is set with
HttpContext.Current.User.Identity.Name.ToString()


 Public Function getUserInfo(ByVal incomingUserName As String) As String
        getUserData = LoadADSIDetails("", incomingUserName)
        Return getUserData
    End Function

Following code starts a loop...
I want to apply a filter somehow

blah...blah...blah...
 Public Function LoadADSIDetails(ByVal Query As String, ByVal incomingUserName As String) As String

        Dim counter As Int16 = 0
        Dim searcher As New DirectorySearcher("")
        Dim DataToWrite As String = Nothing
        Try
            If Query.Trim.Length = 0 Then
                searcher.Filter = "(&(!(userAccountControl:1.2.840.113556.1.4.803:=2))(objectCategory=user))"
            Else
                searcher.Filter = "(&(!(userAccountControl:1.2.840.113556.1.4.803:=2))(objectCategory=user)(" + Query + "))"
            End If
            searcher.SearchScope = SearchScope.Subtree


            Dim FirstName, SurName, Email, UserName, GroupName As String

            For Each result As SearchResult In searcher.FindAll()

            blah...blah...blah...

Open in new window

Larry Bristersr. DeveloperAsked:
Who is Participating?
 
Julian123Commented:
Here's an example with a filter:

Dim oroot As DirectoryEntry = New DirectoryEntry("LDAP://my.domain.local";)
 Dim osearcher As DirectorySearcher = New DirectorySearcher(oroot)
 Dim oresult As SearchResultCollection
 Dim result As SearchResult
 
osearcher.Filter = "(&(sAMAccountName=jsmith))"
 oresult = osearcher.FindAll
 
For Each result In oresult
  If Not result.GetDirectoryEntry.Properties("SAMAccountName").Value Is
 Nothing Then
   Response.Write(result.GetDirectoryEntry.Properties("SAMAccountName").Value
 & "<br />")
  End If
 Next
0
 
YZlatCommented:
what is Query?
0
 
Larry Bristersr. DeveloperAuthor Commented:
Great!

Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.