Avatar billede surre Nybegynder
03. marts 2006 - 11:37 Der er 1 løsning

Problem with System.DirectoryServices.SortOption (LDAP)

I'm fetching an LDAP list of persons and it works fine except from that the result comes out unsorted. I want to sort by surname and have tried using System.DirectoryServices.SortOption. But when I add the sort code I get the exception: System.Runtime.InteropServices.COMException: Incorrect function, on the line where I call mySearcher.FindAll(). Without the SortOption lines it works fine. I'm not that familiar with DirectoryServices and LDAP so any help would be great!

This is part of my code :

...

Dim entry As New DirectoryServices.DirectoryEntry("LDAP://xxx")
Dim mySearcher As New System.DirectoryServices.DirectorySearcher(entry)
Dim result As System.DirectoryServices.SearchResult
Dim arrPerson As New ArrayList
Dim sortOption = New System.DirectoryServices.SortOption("sn", System.DirectoryServices.SortDirection.Descending)
mySearcher.Filter = ("sn=" & letter & "*")  'letter is a parameter containing the letter that the surname shall begin with
mySearcher.PropertiesToLoad.Add("uid")
mySearcher.PropertiesToLoad.Add("givenName")
mySearcher.PropertiesToLoad.Add("sn")
mySearcher.Sort = sortOption
For Each result In mySearcher.FindAll() 'here is where the exception occurs
  arrPerson.Add(New Person(result.GetDirectoryEntry.Properties.Item("uid").Value, result.GetDirectoryEntry.Properties.Item("givenName").Value, result.GetDirectoryEntry.Properties.Item("sn").Value))
Next
Avatar billede surre Nybegynder
06. marts 2006 - 14:07 #1
I'm moving this question with a higher point
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
IT-kurser om Microsoft 365, sikkerhed, personlig vækst, udvikling, digital markedsføring, grafisk design, SAP og forretningsanalyse.

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester