SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

We're developing a custom web part that displays information from a list about the user. We need to determine who's profile page we're on to retrieve the appropriate information from the list. The UserProfileManager needs an account to retrieve a specific profile so that won't work.

share|improve this question
up vote 0 down vote accepted

The query string isn't reliable, it varies depending on how you get to the user's page (eg: clicking "My Profile", browsing from search results, using the pretty url "/personal/username", etc...).

From your web part, you can get the profile the same way that all of the controls on the user's profile get it (using the ProfilePropertyLoader):

var profileLoader = Microsoft.SharePoint.Portal.WebControls.ProfilePropertyLoader.FindLoader(this.Page);
var userProfile = profileLoader.ProfileLoaded;
var username = userProfile["UserName"].Value;
share|improve this answer
If you are ON the My Site Host, this is the best approach. – Matthew McDermott Jun 15 '12 at 14:47

UserProfileManager has two overloads to get user profile - with GetUserProfile(bool bCreateIfNotExist) - this gets user profile, or creates if it is not exists, and GetUserProfile(string strAccountName).
If you are talking about my site host, then you can determine who's profile page you're on by query string parameter. If you are viewing somebody's account, query string looks like follows: ?accountName=domain\user_name. You can determine user by this query string.

share|improve this answer

Your Answer


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.