Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Professional
|
ASP.NET 1.0 and 1.1 Professional For advanced ASP.NET 1.x coders. Beginning-level questions will be redirected to other forums. NOT for "classic" ASP 3 or the newer ASP.NET 2.0 and 3.5
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 8th, 2006, 08:19 AM
Registered User
 
Join Date: Mar 2006
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem with System.DirectoryServices.SortOption

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("u id").Value, result.GetDirectoryEntry.Properties.Item("givenNam e").Value, result.GetDirectoryEntry.Properties.Item("sn").Val ue))
Next

I have also tried a variant with
mySearcher.Sort.PropertyName="sn"
mySearcher.Sort.Direction = "descending"
instead of the above sort syntax but it still doesn't work. I suspect that the sort code in fact is correct, since I have seen others using the exact same syntax examples but since I have no clue what the exception message "invalid function" could refer to, and why it occurs on the specific line I have marked out, I don't know where to look for what's causing the error. Without the sorting I get the list, but unsorted, and I really need it to be sorted...






Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with a system BigH140 Access 3 February 6th, 2006 04:57 PM
System.Security problem jdang67 General .NET 1 November 14th, 2005 01:24 PM
Unable to use System.DirectoryServices planeswalk Pro VB.NET 2002/2003 5 November 12th, 2004 06:23 PM
system.mdw problem stoneman Access 7 September 14th, 2004 09:46 AM
Unable to use System.DirectoryServices planeswalk VB.NET 0 June 24th, 2003 11:24 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.