Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I'm using the User Profile Service Application in SharePoint 2010 which contains imported user profiles.

Now I want to display a list of all users who have a profile, to show a list like "my colleagues". But the Profile Service API doesn't seem to have a way to get all user profiles.

I suspect this is due to performance reasons, but even so, what would be a way to actually retrieve all profiles?

using .AllUsers feels problematic since it doesn't match the list of profiles.

share|improve this question
add comment

1 Answer

up vote 5 down vote accepted

This will give you all profiles, without restrictions:

var serviceContext = SPServiceContext.GetContext(site);
var userProfileManager = new UserProfileManager(serviceContext);
foreach (UserProfile userProfile in userProfileManager)
{
    // ...
}

This operation in itself is not super costly, but retrieving individual user profile properties can be.

You'll most likely need to elevate while doing this.

share|improve this answer
1  
Does this get you the user profile from the site collection (user information list) "site" that you pass into "SPServiceContext.GetContext" or does it come from the central User Profile DB that the "User Profile Service Application uses"? I'm hoping that it is the latter but then why would you need to pass in a site collection for context if it's universal to all site collections? –  skeletank Jun 11 '12 at 18:48
    
I have testet it and I can say that it comes from the central User Profile DB :) –  lex Jul 29 '13 at 9:13
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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