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=state,DC=az";string ldapSearchFilter =
"objectClass=computer";
string[] attributesToReturn = { "name" };
int pageSize = 5;
PageResultRequestControl pageRequestControl = new
PageResultRequestControl(pageSize);
PageResultResponseControl pageResponseControl;
SearchResponse searchResponse;
// create a search request: specify baseDn, ldap search filter, attributes
to return and scope of the search
SearchRequest searchRequest = new SearchRequest(targetOU, ldapSearchFilter,
SearchScope.Subtree, attributesToReturn);
searchRequest.Controls.Add(pageRequestControl); //adds the page request
control
int count;
while (true)
{
searchResponse = (SearchResponse)ldapConnection.SendRequest(searchR equest);
Console.WriteLine("\r\nPage: " + searchResponse.Entries.Count + " entries:");
//display the entries in this page
count = 0;
foreach (SearchResultEntry entry in searchResponse.Entries)
{
// retrieve a specific attribute
DirectoryAttribute attribute = entry.Attributes["name"];
Console.WriteLine(++ count + " " + attribute.Name + " = " + attribute[0]);
}
//retrieve the cookie
if (searchResponse.Controls.Length != 1 || !(searchResponse.Controls[0] is
PageResultResponseControl))
{
Console.WriteLine("The server did not return a PageResultResponseControl
as expected.");
return;
}
pageResponseControl = (PageResultResponseControl)searchResponse.Controls[0];
//if responseControl.Cookie.Length is 0 then there are no more pages to
retrieve so break the loop
if (pageResponseControl.Cookie.Length == 0) break;
pageRequestControl.Cookie = pageResponseControl.Cookie;
}
Console.WriteLine("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
(pageResponseControl.Cookie.Length == 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