If my companies AD is the SharePoint user base, how would I get all the employee's First/Last Name and Extension in C#?

I plan on displaying them with SPGridView.

  • Why a grid? Why not use a search query and provide a alphabetical catalog of users by first or last name? The performance will be WAY better and it can be done client side. – Matthew McDermott Mar 11 '17 at 21:16

There is no client side code to iterate through user profiles. You can do through server side, Reference Here

If you have no choice other than client side, there is a workaround. Note:

  1. Your User profile data is perfectly managed.

  2. All users have the proper hierarchy.

Now start with company Top level employee and get all his/her direct reports

_spPageContextInfo.webServerRelativeUrl + "/_api/SP.UserProfiles.PeopleManager/GetPropertiesFor(accountName=@v)?@v='" + encodeURIComponent(accountName) + "'&$select=DirectReports"

After getting all direct reportees to top level/CEO , iterate through these users and try to get their direct reportees, continue looping till you get last or zero direct reportees. This way you will get all employee.


  1. This will skip the user profiles which does not have any manager assigned to them.
  2. Depending on your size of organization it can take too long to run.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.