DirectorySearch sort broke my function!

G

Guest

Hi peeps,

I had a function working fine for retrieving a list of users from Active
Directory. However, client wants it sorted alphabetically. So I added Sort
option to my searcher, and now the code won't run... perhaps someone can tell
me whats up with it, and more importantly how to fix it...

Here's the code...

private void PullADUsers()
{
int listc;
string cs;
DirectoryEntry entry = new DirectoryEntry("LDAP://" +
ConfigurationSettings.AppSettings.Get("System_ActiveDirPath"));
DirectorySearcher mySearcher = new DirectorySearcher(entry);
mySearcher.Filter = ("(objectClass=user)");
mySearcher.Sort = new SortOption("FirstName", SortDirection.Ascending);
listc = 1;
foreach(SearchResult resEnt in mySearcher.FindAll())
{
try
{
DirectoryEntry de = resEnt.GetDirectoryEntry();
if((de.Properties["DisplayName"].Value != null) &&
(de.Properties["givenName"].Value != null) && (de.Properties["sn"].Value !=
null))
{
ListItem adItem = new ListItem();
adItem.Text = de.Properties["givenName"].Value.ToString() + " " +
de.Properties["sn"].Value.ToString();
adItem.Value = de.Properties["sAMaccountname"].Value.ToString();
ddlDartsContact.Items.Insert(listc, adItem);
adItem = null;
listc++;
}
}
catch
{
// my catch code here
}
finally {}
}
}

The error I'm getting is...

Exception Details: System.Runtime.InteropServices.COMException: The server
does not support the requested critical extension

....and occours on the for() line.

Hope someone can help!

Cheers


Dan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top