Reputation: 34028
Currently I have a customized people picker in sharepoint 2010, it searches the search term on the account name, but also on the name.
However its done in 2 different methods. I dont have experience with complex AD queries, but I suppose I can do this in only one and line and with an OR?
What I need is that it matches either, part of the samaccountname OR part of the name
public static DataTable ExecuteNameQuery(string rootPath, string search)
{
string filter = "(&(objectCategory=person)(objectClass=user)(name=*" + search + "*))";
return ExecuteADQuery(rootPath, filter);
}
public static DataTable ExecutesAMAccountNameQuery(string sAMAccountName)
{
string filter = "(&(objectCategory=person)(objectClass=user)(sAMAccountName=*" + sAMAccountName + "*))";
return ExecuteADQuery("GC:", filter);
}
Upvotes: 1
Views: 1218
Reputation: 1527
Yes, you can group and/or operators in LDAP queries using the following syntax, based on your example :
string filter = "(&(objectCategory=person)(objectClass=user)(|(name=*" + search + "*)(samAccountName=*" + search + "*)))";
That should perform the search on either name or samAccountName.
Additionnally, MSDN has a primer on LDAP queries.
Hope that helps
Upvotes: 3