How do I sort LDAP search results?
Some LDAP servers support sorting, in which case you can just specify the attributes you'd like to sort by in the SortCriteria property prior to calling the Search method of the component. For example, to get search results sorted by the cn attribute:
//bind first, if necessary:
ldap.DN = "DOMAIN\\User";
ldap.Password = "mypassword";
ldap.Bind();
ldap.DN = "cn=Users,dc=JUNGLE";
ldap.SortAttributes = "cn";
ldap.Search("objectClass=*");
We appreciate your feedback. If you have any questions, comments, or suggestions about this article please contact our support team at support@nsoftware.com.