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

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
add comment

2 Answers

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
add comment

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
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.