Link to home
Start Free TrialLog in
Avatar of Larry Brister
Larry BristerFlag for United States of America

asked on

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

ASKER CERTIFIED SOLUTION
Avatar of Julian123
Julian123

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of YZlat
what is Query?
Avatar of Larry Brister

ASKER

Great!

Thanks