DirectorySearcher.PageSize Property
.NET Framework 4
Gets or sets a value indicating the page size in a paged search.
Assembly: System.DirectoryServices (in System.DirectoryServices.dll)
| Exception | Condition |
|---|---|
| ArgumentException |
The new value is less than zero. |
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
SizeLimit relation to PageSize
SizeLimit | PageSize | Results Return
-----------|-------------|-----------------
1005 | 1100 | 1005(?)
tested it and apparently returned 1000 to me. So when PageSize > SizeLimit and SizeLimit > 1000 it returnes the server-determined default (1000).
-----------|-------------|-----------------
1005 | 1100 | 1005(?)
tested it and apparently returned 1000 to me. So when PageSize > SizeLimit and SizeLimit > 1000 it returnes the server-determined default (1000).
- 9/19/2011
- Qutory
Helpful..
Thanks for the additional community content - MS Examples are 'barebones' at times - this saved me enough time to justify adding an example usage from one of my wrapper functions
public SearchResultCollection SearchDirectory(string FilterString = "", DirectoryEntry StartFromHere = null,int MaxResults=Int32.MaxValue-1)
{
if (StartFromHere == null)
{ StartFromHere = new DirectoryEntry(CurrentDomainProperties.ADLDAPRootNodeSearchPath()); }
DirectorySearcher searcher = new DirectorySearcher(StartFromHere);
searcher.SizeLimit = MaxResults;
searcher.PageSize = 1000;
searcher.Filter = string.Format(FilterString);
......
This quite happily returns 5000+ results on my machine..
public SearchResultCollection SearchDirectory(string FilterString = "", DirectoryEntry StartFromHere = null,int MaxResults=Int32.MaxValue-1)
{
if (StartFromHere == null)
{ StartFromHere = new DirectoryEntry(CurrentDomainProperties.ADLDAPRootNodeSearchPath()); }
DirectorySearcher searcher = new DirectorySearcher(StartFromHere);
searcher.SizeLimit = MaxResults;
searcher.PageSize = 1000;
searcher.Filter = string.Format(FilterString);
......
This quite happily returns 5000+ results on my machine..
- 7/28/2011
- lojk
SizeLimit relation to PageSize
Since it was unclear i figured a chart might be the easiest way to
explain how SizeLimit and PageSize relate to each other. If the
PageSize is greater than the SizeLimit you will retrieve up to the
SizeLimit. If the SizeLimit is greater than the PageSize you will
retrieve all matching results. If the PageSize is the default of "0"
then you will retrieve the SizeLimit OR 1000, whichever is smaller.
Personally I think there is a bug in how this works cause it was against
my, and possible others expectations of how this work. I added the
last line where the PageSize is over 1000, but don't have data to test
whether or not that returns 1005 results or if it errors out cause
PageSize has a limit.
SizeLimit | PageSize | Results Return
-----------|-------------|-----------------
50 | 0 | 50
50 | 100 | 50
50 | 5 | All
1005 | 0 | 1000
1005 | 1 | All
1005 | 50 | All
1005 | 1100 | 1005(?)
SizeLimit | PageSize | Results Return
-----------|-------------|-----------------
50 | 0 | 50
50 | 100 | 50
50 | 5 | All
1005 | 0 | 1000
1005 | 1 | All
1005 | 50 | All
1005 | 1100 | 1005(?)
- 1/24/2011
- Squarebox
Only getting 1000 search results?
What this documentation fails to mention is that if you do not set the PageSize property (or if you set it to 0) then you will only ever get a maximum of 1000 search results brought back by the DirectorySearcher.FindAll method. It also does not make it very clear that you dont actually have to do anything to request more data in a paged search - simply set the PageSize property to 1000 and everything is taken care of for you.
- 8/23/2010
- Chris128