DirectorySearcher Class
Assembly: System.DirectoryServices (in system.directoryservices.dll)
Use a DirectorySearcher object to search and perform queries against an Active Directory hierarchy using Lightweight Directory Access Protocol (LDAP). LDAP is the only system-supplied Active Directory Service Interfaces (ADSI) provider that supports directory searching. An administrator can make, alter, and delete objects that are found in the hierarchy. For more information, see Using System.DirectoryServices.
When you create an instance of DirectorySearcher, you specify the root you want to retrieve, and an optional list of properties to retrieve. The SearchRoot property enables you to set additional properties to do the following tasks:
-
Cache the search results on the local computer. Set the CacheResults property to true to store directory information on the local computer. Updates are made to this local cache and committed to Active Directory only when the DirectoryEntry.CommitChanges method is called.
-
Specify the length of time to search, using the ServerTimeLimit property.
-
Retrieve attribute names only. Set the PropertyNamesOnly property to true to retrieve only the names of attributes to which values have been assigned.
-
Perform a paged search. Set the PageSize property to specify the maximum number of objects that are returned in a paged search. If you do not want to perform a paged search, set the PageSize property to its default of zero.
-
Specify the maximum number of entries to return, using the SizeLimit property. If you set the SizeLimit property to its default of zero, the server-determined default is 1000 entries.
Note: |
|---|
| If the maximum number of returned entries and time limits exceed the limitations that are set on the server, the server settings override the component settings. |
For a list of initial property values for an instance of the DirectorySearcher class, see the DirectorySearcher constructor.
Note: |
|---|
| It is assumed that you have a general understanding of Active Directory before using this class. For more information, see the System.DirectoryServices overview. |
System.MarshalByRefObject
System.ComponentModel.Component
System.DirectoryServices.DirectorySearcher
Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.Reference
DirectorySearcher MembersSystem.DirectoryServices Namespace
DirectoryEntries
DirectoryEntry
DirectorySearcher
DirectorySearcher
PropertyCollection
PropertyValueCollection
ReferralChasingOption
SearchResultCollection
SearchResult
ResultPropertyValueCollection
SearchScope
SortDirection
SortOption
When using the DirectorySearcher to access a DirX system via anonymous authentication and passing a DirectoryEntry into the DirectorySearcher constructor, the username and password must be explicitly set to String.Empty and the Authentication type must be explicity set to Anonymous.
Example:
DirectoryEntry mBaseSearchPathEntry = new DirectoryEntry("LDAP://" + mLdapServer + mLdapSearchPath, String.Empty, String.Empty, AuthenticationTypes.Anonymous);
DirectorySearcher employeeFinder = new DirectorySearcher(mBaseSearchPathEntry);
- 6/28/2007
- Mark Squires - MCAD
There is a delicate balance between PageSize and SizeLimit.
That is, if you don't set PageSize then you will only get 1000 results, not matter how many results there are.
Counterintuitively, increasing the SizeLimit doesn't help - instead, you should set the PageSize to be 1000. This is the only change you need to make.
The reason for this, is that SizeLimit limits the amount of results that you can retrieve at once - so your PageSize needs to be less than or equal to this. The paging is done automagically behind the scenes when you call FindAll() etc.
- 6/27/2006
- ShaunMcCarthy
- 6/28/2006
- ShaunMcCarthy
Note: