Hi!
Im having some problem in my function to search on all users in my active directory, root and subtree.
my ad is like this:
ad.company
-> se.ad.company
-> fin.ad.company
-> no.ad.company
I can search , but only get some results from ad.company, not the other subtree directorys.
What have i done wrong?
And this is my code:
Im having some problem in my function to search on all users in my active directory, root and subtree.
my ad is like this:
ad.company
-> se.ad.company
-> fin.ad.company
-> no.ad.company
I can search , but only get some results from ad.company, not the other subtree directorys.
What have i done wrong?
And this is my code:
C#:
private void AutoCompleteTextBox_ReferenceUser()
{
try
{
var attributeName = "sn";
string OU = "DC=ad,DC=company";
var searchString = textBox_manager.Text;
var ent = new DirectoryEntry("GC://" + OU);
var mySearcher = new DirectorySearcher(ent);
mySearcher.Filter = string.Format("(&(anr={0})(objectCategory=user)(objectClass=user))", attributeName, searchString);
SearchResultCollection result = mySearcher.FindAll();
List<string> names = new List<string>();
foreach(SearchResult sr in result)
{
var n = sr.Properties["cn"][0].ToString();
if (!names.Contains(n))
{
stringCollection.Add(n);
}
}
textBox_referenceuser.AutoCompleteMode = AutoCompleteMode.Suggest;
textBox_referenceuser.AutoCompleteSource = AutoCompleteSource.CustomSource;
textBox_referenceuser.AutoCompleteCustomSource = stringCollection;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}