AD Programming in .net

G

Guest

hi all
I am trying to get list of employees in an organization based on the lastname, firstname. Things work fine if i give either firstname or lastname but stops working if i give lastname,firstname

string uname="ba,joh"
string filter="(&(anr=" + uname + ")(|(objectCategory=organizationalPerson)(objectCategory=group)))";
DirectoryEntry entry=new DirectoryEntry("GC://something")
DirectorySearcher dsearch=new DirectorySearcher(entry)
dsearch.Filter=filter
SearchResultCollection result =dsearch.FindAll();
foreach(SearchResult res in result

MessageBox.Show(res.Properties["cn"][0].ToString())


Any idea why the code breaks?? Any help is much appreciated.

thanks in advance

Rav
 
P

Paul Clement

¤ hi all,
¤ I am trying to get list of employees in an organization based on the lastname, firstname. Things work fine if i give either firstname or lastname but stops working if i give lastname,firstname.
¤
¤
¤ string uname="ba,joh";
¤ string filter="(&(anr=" + uname + ")(|(objectCategory=organizationalPerson)(objectCategory=group)))";
¤ DirectoryEntry entry=new DirectoryEntry("GC://something");
¤ DirectorySearcher dsearch=new DirectorySearcher(entry);
¤ dsearch.Filter=filter;
¤ SearchResultCollection result =dsearch.FindAll();
¤ foreach(SearchResult res in result)
¤ {
¤ MessageBox.Show(res.Properties["cn"][0].ToString());
¤ }
¤
¤ Any idea why the code breaks?? Any help is much appreciated..

ANR (Ambiguous Name Resolution) searches are divided at a space and not a comma:

string uname="ba joh";


Paul ~~~ (e-mail address removed)
Microsoft MVP (Visual Basic)
 

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

Top