Export (0) Print
Expand All
0 out of 12 rated this helpful - Rate this topic

Setting Search Filters 

Search filters enable filtering for specific objects by searching for objects based on attributes associated to the object, such as the objectClass. To do this, set up a filter string with the desired attributes included in the string. For wildcard searches, you can enter any part of the string you wish to search on along with a *, such as (anr=test*). When setting up search filters to use with System.DirectoryServices, follow the syntax rules for LDAP filters. To indicate that a filter is used, use the DirectorySearcher property Filter.

For more information about search filters, see the topic Creating a Query Filter in the MSDN Library at http://msdn.microsoft.com/library. For more information about the objectClass attribute, see the topic objectClass in the MSDN Library at http://msdn.microsoft.com/library.

The following code example shows how to add a search filter.

DirectoryEntry entry = new DirectoryEntry("LDAP://CN=users,DC=fabrikam,DC=com");
DirectorySearcher mySearcher = new DirectorySearcher(entry);
mySearcher.Filter = "(&(objectClass=user)(anr=test*))";
SearchResultCollection ResEnt = mySearcher.FindAll();
{
// Handle results.
}
// Handle exceptions.
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.