Skip to content

Instantly share code, notes, and snippets.

@gunnarmagholder
Created April 13, 2016 11:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gunnarmagholder/ef2e2dd5204ec8c2830514edfc5fac96 to your computer and use it in GitHub Desktop.
Save gunnarmagholder/ef2e2dd5204ec8c2830514edfc5fac96 to your computer and use it in GitHub Desktop.
public IEnumerable<UserAccount> GetPage(string sortField, int start, int Number)
{
UserPrincipalEx findAllUsers = new UserPrincipalEx(thisOU);
PrincipalSearcher ps = new PrincipalSearcher(findAllUsers);
((DirectorySearcher) ps.GetUnderlyingSearcher()).PageSize = 0;
((DirectorySearcher)ps.GetUnderlyingSearcher()).Sort = new SortOption("cn", SortDirection.Ascending);
((DirectorySearcher)ps.GetUnderlyingSearcher()).VirtualListView = new DirectoryVirtualListView(0, Number, start);
PrincipalSearchResult<Principal> result = ps.FindAll();
foreach (UserPrincipalEx user in result)
{
string firstName = user.GivenName;
string lastName = user.Surname;
string orgKennzeichen = user.ExtensionAttribute8;
string samAccountName = user.SamAccountName;
UserAccount _user = new UserAccount()
{
FirstName = firstName,
LastName = lastName,
OrgKennzeichen = orgKennzeichen,
SAMAccountName = samAccountName
};
yield return _user;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment