Last post Feb 12, 2015 10:03 AM by togovi
Apr 14, 2008 08:39 AM|soyka|LINK
I have got a following function which returns a collection of Principal objects. Could someone please advice me on how to sort the collection as I'm completely blank on genericity. Any help would be greatly appreciated.
ps.QueryFilter = u
Jun 05, 2009 01:58 PM|lanphi|LINK
Cast your resluts to a list. You can then sort the list using Linq or soemthing like that. I have a code snippet below that shows how to return your results in the form of an IEnumerable collection. You can then use the standard LINQ sorting methods.
private static IEnumerable<UserPrincipal> SearchFirstName(string searchText, PrincipalContext context)
List<UserPrincipal> retVal = null;
using (UserPrincipal u = new UserPrincipal(context))
u.GivenName = searchText;
using (PrincipalSearcher searcher = new PrincipalSearcher(u))
searcher.QueryFilter = u;
retVal = (from principal in searcher.FindAll() select principal as UserPrincipal).ToList();
Feb 12, 2015 10:03 AM|togovi|LINK
results = ps.FindAll().OrderBy( x=> x.SamAccountName)