Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You need to set DirectorySearcher.PageSize to a non-zero value to get all results.</p> <p>BTW you should also dispose DirectorySearcher when you're finished with it</p> <pre><code>using(DirectorySearcher srch = new DirectorySearcher(dirEnt, "(objectClass=Group)", loadProps)) { srch.PageSize = 1000; var results = srch.FindAll(); } </code></pre> <p>The API documentation isn't very clear, but essentially:</p> <ul> <li><p>when you do a paged search, the SizeLimit is ignored, and all matching results are returned as you iterate through the results returned by FindAll. Results will be retrieved from the server a page at a time. I chose the value of 1000 above, but you can use a smaller value if preferred. The tradeoff is: using a small PageSize will return each page of results faster, but will require more frequent calls to the server when iterating over a large number of results.</p></li> <li><p>by default the search isn't paged (PageSize = 0). In this case up to SizeLimit results is returned.</p></li> </ul> <p>As Biri pointed out, it's important to dispose the SearchResultCollection returned by FindAll, otherwise you may have a memory leak as described in the Remarks section of the MSDN documentation for DirectorySearcher.FindAll: <a href="http://msdn.microsoft.com/en-us/library/system.directoryservices.directorysearcher.findall.aspx" rel="noreferrer">http://msdn.microsoft.com/en-us/library/system.directoryservices.directorysearcher.findall.aspx</a></p> <p>One way to help avoid this in .NET 2.0 or later is to write a wrapper method that automatically disposes the SearchResultCollection. This might look something like the following (or could be an extension method in .NET 3.5):</p> <pre><code>public IEnumerable&lt;SearchResult&gt; SafeFindAll(DirectorySearcher searcher) { using(SearchResultCollection results = searcher.FindAll()) { foreach (SearchResult result in results) { yield return result; } } // SearchResultCollection will be disposed here } </code></pre> <p>You could then use this as follows:</p> <pre><code>using(DirectorySearcher srch = new DirectorySearcher(dirEnt, "(objectClass=Group)", loadProps)) { srch.PageSize = 1000; var results = SafeFindAll(srch); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload