0

I am connecting to LDAP and i am getting only classobject of type user, and i want only to get the Distinguished Name, when i dont do any sorting, (I comment the line of sorting) the results are coming just fine, the number of users are 13. and i can print them all, but they are not brought in Ascending order, so i did the sort based on the distinguishedName, when i add these lines to the code, it give me an empty collection of searchResults.

I DONT KNOW WHY, why when i do sorting, the data goes, and when i stop the sorting the data is there. whats wrong with the sorting???

DirectoryEntry entry = new DirectoryEntry(_path, username, 
DirectorySearcher mySearcher = new DirectorySearcher(entry);
mySearcher.Filter = ("(objectClass=user)");
SortOption option = new SortOption("distinguishedName", System.DirectoryServices.SortDirection.Ascending);
mySearcher.Sort = option;
DataSet ds = new DataSet();
DataTable dtUsers = new DataTable("Users");
dtUsers.Columns.Add("distinguishedName");
SearchResultCollection ss = mySearcher.FindAll();
SearchResult a = ss[0];
Chuck Savage
  • 11,775
  • 6
  • 49
  • 69
msytNadeem
  • 173
  • 1
  • 4
  • 15

2 Answers2

0

Do the sort in DataView something like this:

DataTable dtUsers = new DataTable("Users");
dtUsers.Columns.Add("distinguishedName");
DataView view = dtUsers.DefaultView;
view.Sort = "distinguishedName";
Crilledk
  • 3
  • 4
0

FWIW, my recommend would typically be to not sort server side. The client can easily sort and keep the sort load off of the DC. There are a few cases where you really need the server to sort, but if you can avoid it, I would. Your admins will thank you.

Eric Fleischman
  • 1,168
  • 6
  • 8