AD DirectorySearcher problem with SearchResultCollection class

N

nscarnati

I have 2 containers with objects. The veterans container contains
unique objects. Each of those objects can have 1 or more corresponding
card objects in the cards container.

VeteranCN is formatted (SSN-LastName)
CardsCN is formatted (SSN-LastName-# OR SSN-LastName-#CNFblahblahblah)
(the # is the card number)

I have the following code, which searches a container for objects. It
creates the value that will be used for the next card object by
querying the cards for that user and adding 1 to it which will be a new
object (the creation of the object is done in other code not shown -
this is just to figure out what the new object will be called). Right
now, I am just getting a count of the number of results from the query
and adding 1 to it - the problem with that is the results may include
error objects (formatted SSN-LastName-#CNF) so using the Count of the
results will give me the wrong number. For example:
The query results could be:
123456789-Smith-1
123456789-Smith-2
123456789-Smith-3
123456789-Smith-3CNFnjrgnelrkjgne489t3hth
123456789-Smith-4
123456789-Smith-5

If the above were the LDAP query results, my code would name the new
object 123456789-Smith-7 and NOT 123456789-Smith-6 which it SHOULD be.

So basically I need to modify my code to pull the highest number from
the results. I think you would use the Item member to somehow loop
through the SearchResultsCollection, but I'm clueless how to do that.
Any suggestions or how this can be done would be appreciated. Thanks




Dim oSearcher As DirectorySearcher = New DirectorySearcher(oroot)
Dim oResults As SearchResultCollection
Dim oResult As SearchResult

'gets the AD objects
oSearcher.PropertiesToLoad.Add("cn")

oSearcher.Filter = "(cn=" & AllRecords.Rows(currentrow)("VeteranCN") &
"*" & ")"
oResults = oSearcher.FindAll

'create Cards CN based on what the highest current Cards CN is
If oResults.Count < 1 Then
AllRecords.Rows(currentrow)("NewCardsCN") =
AllRecords.Rows(currentrow)("VeteranCN") & "-1"
End If

If oResults.Count = 1 Then
AllRecords.Rows(currentrow)("NewCardsCN") =
AllRecords.Rows(currentrow)("VeteranCN") & "-2"
End If

If oResults.Count > 1 Then
AllRecords.Rows(currentrow)("NewCardsCN") =
AllRecords.Rows(currentrow)("VeteranCN") & "-" & (oResults.Count + 1)
End If
 
N

nscarnati

If it possible to create a search filter that excludes results where
CNF is anywhere in the CN, but still contains the search criteria?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top