I am trying to achieve my first attempt to at reading Active Directory entries into a SearchResultCollection.
At this stage I'm just trying to return a list of the 'cn' property.
I run the code below - with a valid DirectoryEntry address of course.
The code tootles along and returns the 'results' collection with a count of 63.
I have assumed the count means the 63 entries have been returned.
The code then fails on the line:-
MessageBox.Show(result.Properties("cn")(0))
The error message is {"Index was out of range. Must be non-negative and less than the size of the collection.Parameter name: index"}.
Any suggestions/help would be welcome.
Dazed and confused.
Remember.. 'Depression is just anger without enthusiasum'.
At this stage I'm just trying to return a list of the 'cn' property.
I run the code below - with a valid DirectoryEntry address of course.
The code tootles along and returns the 'results' collection with a count of 63.
I have assumed the count means the 63 entries have been returned.
The code then fails on the line:-
MessageBox.Show(result.Properties("cn")(0))
The error message is {"Index was out of range. Must be non-negative and less than the size of the collection.Parameter name: index"}.
Any suggestions/help would be welcome.
Code:
Try
' Bind to the users container.
Dim rootentry As New DirectoryEntry("LDAP://.........................................")
rootentry.Username = Nothing
rootentry.Password = Nothing
' Create a DirectorySearcher object.
Dim Searcher As New DirectorySearcher(rootentry)
Searcher.PropertiesToLoad.Add("cn")
Dim results As SearchResultCollection
results = Searcher.FindAll()
Dim result As SearchResult
For Each result In results
MessageBox.Show(result.Properties("cn")(0))
Next
Catch comEx As System.Runtime.InteropServices.COMException
Console.WriteLine(comEx)
Catch invOpEx As InvalidOperationException
Console.WriteLine(invOpEx)
Catch ex As Exception
MsgBox("Error " & vbCrLf & ex.Message)
End Try
Dazed and confused.
Remember.. 'Depression is just anger without enthusiasum'.