Connecting Tech Pros Worldwide Forums | Help | Site Map

Active Directory problem - search.FindAll()

mg
Guest
 
Posts: n/a
#1: Nov 18 '05
I'm able to connect to AD and retrieve the value of mail for one user (for example, "jones") successfully, with the following code

public void lookupOne(

String domainAndUsername = domain + @"\" + username
DirectoryEntry entry = new DirectoryEntry(_path, domainAndUsername, pwd)

tr
{
Object obj = entry.NativeObject

DirectorySearcher search = new DirectorySearcher(entry)

search.Filter = "(SAMAccountName=" + username + ")"

search.PropertiesToLoad.Add("mail")

SearchResult result = search.FindOne()

_path = result.Path

_filterAttribute = (String)result.Properties["mail"][0]

Label1.Text = _path

Label2.Text = _filterAttribute

catch (Exception ex){



But, I want to retrieve the mail addresses for all users whose names are "jon*". The following code doesn't work - it throws an exception. Can someone tell me what I need to do here

public void lookupAll(


String domainAndUsername = domain + @"\" + username
DirectoryEntry entry = new DirectoryEntry(_path, domainAndUsername, pwd)

tr
{
Object obj = entry.NativeObject

DirectorySearcher search = new DirectorySearcher(entry);

search.PropertiesToLoad.Add("mail")

search.Filter = "(&(objectclass=user)(sAMAccountName=" + UserName + "))"

SearchResultCollection resultCollection = search.FindAll()

Label1.Text = resultCollection.Count.ToString()


catch (Exception ex) {


Closed Thread