-1

Possible Duplicate:
Can I get more than 1000 records from a DirectorySearcher in Asp.Net?
c# Active Directory Services findAll() returns only 1000 entries

I have a problem when trying read all user from AD. Active directory contain over 3000 user, but I can read only 1000. This is my code

public DirectoryEntry directoryEntry = new DirectoryEntry(ldap, userName, password);
public DirectorySearcher directorySearcher = new DirectorySearcher(directoryEntry);

var allUsers = directorySearcher.FindAll();
Community
  • 1
  • 1
mir89
  • 95
  • 1
  • 8
  • If the limit were arbitrary or a non-round number, I'd grant that this was a good question. But as it stands, a quick Google / SO search might have saved you the trouble. http://stackoverflow.com/questions/90652/can-i-get-more-than-1000-records-from-a-directorysearcher-in-asp-net – Wim Ombelets Feb 04 '13 at 12:58

2 Answers2

3

It is a user settings problem. According to this page you have to set the page size to 1000 to get more than 1000 results:

OmegaMan: Ya its bizarre, one has to set a page size as 1000 to get more records than 1000. This is a trick/issue one doesn't forget due to the way one has to resolve the problem.

jwillmer
  • 3,570
  • 5
  • 37
  • 73
2

You need to set the PageSize property on your DirectorySearcher to get paged searching and more than 1000 rows back:

public DirectoryEntry directoryEntry = new DirectoryEntry(ldap, userName, password);

public DirectorySearcher directorySearcher = new DirectorySearcher(directoryEntry);
directorySearcher.PageSize = 500;  // ADD THIS LINE HERE !

var allUsers = directorySearcher.FindAll();
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459