Counting results in Object

dakota367

New member
Joined
Oct 15, 2009
Messages
2
Programming Experience
3-5
Hello,

I have a small application that I am using to get some information out of Active Directory. I am running this task on a different thread because sometimes it can be a timely process. I need a way to count all the results in the .findone() function before I start looping through the results of the search so that I can report this number to my application main form. Thanks so much for any help in advance.


VB.NET:
Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
        Dim GroupSearcher As New DirectorySearcher
        Dim resultsarray(6) As String
   
        Dim GroupSearchRoot As New DirectoryEntry("LDAP://DC=root,DC=domain,DC=org")

        With GroupSearcher
            .SearchRoot = GroupSearchRoot
            .Filter = "(&(ObjectClass=Group)(CN=" & TextBox1.Text & "))"  '<<<Group Name
        End With

        Dim Members As Object = GroupSearcher.FindOne.GetDirectoryEntry.Invoke("Members", Nothing) '<<< Get members
        



        For Each Member As Object In CType(members, IEnumerable)  '<<< loop through members
            Dim CurrentMember As New DirectoryEntry(Member) '<<< Get directoryentry for user

            resultsarray(0) = CurrentMember.Properties.Item("displayName").Value
            resultsarray(1) = CurrentMember.Properties.Item("samAccountName").Value
            resultsarray(2) = CurrentMember.Properties.Item("mail").Value
            resultsarray(3) = CurrentMember.Properties.Item("department").Value
            resultsarray(4) = CurrentMember.Properties.Item("title").Value
            resultsarray(5) = CurrentMember.Properties.Item("manager").Value
            resultsarray(6) = CurrentMember.Properties.Item("company").Value
            BackgroundWorker1.ReportProgress(0, resultsarray)
        Next
    End Sub
 
Back
Top