Directory Searcher Multi-Sort

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am a newbie to .NET. I am coding a web part for SPS that returns all of
the users from an Active Directory tree, sorted by attribute x (in this case,
Company). This works fine.

How can I sort the results within each company by a separate criterion
(e.g., alphabetically by last name). I am sure that I could do this by
building myself a multi-dimensional array from the objects in my
searchresultcollection prior to rendering the information in my web part, but
I would think there is an easier way.

Can you perform a sort on multiple attributes using the DirectorySearcher
object? If so, where can I find an example of the syntax to accomplish this?

Thanks in advance.

Joe
 
Can you perform a sort on multiple attributes using the DirectorySearcher
object? If so, where can I find an example of the syntax to accomplish this?

No, you cannot per se - out of the box. However, what you CAN do, is
stash your results (e.g. the list of objects of type "SearchResult")
into a collection, and apply a custom sorter to that collection.

Read up on collections (esp. ArrayList) and custom comparers in your
MSDN docs - you can basically write your own little class that
compares two of your objects (whatever they might be), and determines
whichever of the two is comes first. This can be used by the basic
..Sort method on the ArrayList to sort your objects in any order you
might want them to be sorted in.

Marc

================================================================
Marc Scheuner May The Source Be With You!
Bern, Switzerland m.scheuner(at)inova.ch
 
Back
Top