LDAP searchobject should support paging
Frends.LDAP.SearchObjects is a great way to work with Active Directory but we are currently limited if there are more than 1000 objects. Most LDAP servers (like Active Directory) enforce a server-side size limit on search results, typically 1000 entries by default. However, you can work around this limitation using paging. By using paging, you can efficiently retrieve more than 1000 objects from LDAP without overloading the server or hitting size limits. Using Paging with DirectorySearcher Paging allows you to request a subset of the results (e.g., 500 entries at a time) until all objects are retrieved. Example Code: using System; using System.DirectoryServices; class LDAPSearch { static void Main() { string ldapPath = "LDAP://YourDomainController"; string searchFilter = "(objectClass=user)"; // Adjust your filter as needed using (DirectoryEntry entry = new DirectoryEntry(ldapPath)) { using (DirectorySearcher searcher = new DirectorySearcher(entry)) { searcher.Filter = searchFilter; searcher.PageSize = 500; // Enables paging (e.g., 500 results per page) searcher.PropertiesToLoad.Add("distinguishedName"); // Load only necessary properties try { // Execute the search SearchResultCollection results; do { results = searcher.FindAll(); foreach (SearchResult result in results) { Console.WriteLine(result.Properties"distinguishedName"); } // Automatically handled by PageSize } while (results != null && results.Count > 0); } catch (Exception ex) { Console.WriteLine($"Error: {ex.Message}"); } } } } }
