Okay, I found an example of using paged serches in the MSDN Library for
VS2005. I copied the paged search section of the code and modified to fit
out AD structure...
---code copy
static void Main(string[] args)
{
//connect to domain controller
LdapConnection ldapConnection = new LdapConnection( "DC1.dot.state. az");
//set filter options
string targetOU = "DC=dot,DC=stat e,DC=az";string ldapSearchFilte r =
"objectClass=co mputer";
string[] attributesToRet urn = { "name" };
int pageSize = 5;
PageResultReque stControl pageRequestCont rol = new
PageResultReque stControl(pageS ize);
PageResultRespo nseControl pageResponseCon trol;
SearchResponse searchResponse;
// create a search request: specify baseDn, ldap search filter, attributes
to return and scope of the search
SearchRequest searchRequest = new SearchRequest(t argetOU, ldapSearchFilte r,
SearchScope.Sub tree, attributesToRet urn);
searchRequest.C ontrols.Add(pag eRequestControl ); //adds the page request
control
int count;
while (true)
{
searchResponse = (SearchResponse )ldapConnection .SendRequest(se archRequest);
Console.WriteLi ne("\r\nPage: " + searchResponse. Entries.Count + " entries:");
//display the entries in this page
count = 0;
foreach (SearchResultEn try entry in searchResponse. Entries)
{
// retrieve a specific attribute
DirectoryAttrib ute attribute = entry.Attribute s["name"];
Console.WriteLi ne(++ count + " " + attribute.Name + " = " + attribute[0]);
}
//retrieve the cookie
if (searchResponse .Controls.Lengt h != 1 || !(searchRespons e.Controls[0] is
PageResultRespo nseControl))
{
Console.WriteLi ne("The server did not return a PageResultRespo nseControl
as expected.");
return;
}
pageResponseCon trol = (PageResultResp onseControl)sea rchResponse.Con trols[0];
//if responseControl .Cookie.Length is 0 then there are no more pages to
retrieve so break the loop
if (pageResponseCo ntrol.Cookie.Le ngth == 0) break;
pageRequestCont rol.Cookie = pageResponseCon trol.Cookie;
}
Console.WriteLi ne("Complete.") ;
--end
This still only returns one page of data with the size limit I set but no
more than 1000.
I set a break point steped through the code. On the first pass, when their
should be more pages waiting, this line of code "if
(pageResponseCo ntrol.Cookie.Le ngth == 0) break;" evaluates to true and the
code breakes out of the loop.
What am I missing?
Thanks!
"Marc Scheuner [MVP ADSI]" wrote:
Why does my LDAP query from a C# console app limit its results to 1000?
That's by design - you can get around it by explicitly specifying a
"page size" - in that case, the LDAP server will send you the results
in chunks of "page size" items at a time.
Marc
=============== =============== =============== =============== ====
Marc Scheuner May The Source Be With You!
Berne, Switzerland m.scheuner -at- inova.ch