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

How to get the users image in my site programatically?

I need to show image of the logged-in user in my webpart.

share|improve this question
up vote 7 down vote accepted

The function below will get you the UserProfile based on the accountName

public static UserProfile GetUserInfo(string AccountName)
    UserProfile profile = null;
    SPServiceContext serviceContext = SPServiceContext.Current;
    UserProfileManager profileManager = new UserProfileManager(serviceContext);
    if (AccountName != string.Empty)
        profile = profileManager.GetUserProfile(AccountName);
        profile = profileManager.GetUserProfile(SPContext.Current.Web.CurrentUser.RawSid);
    return profile;

The picture URL will be in

share|improve this answer
Can I set Picture of User Profile without configuring mySite ? – Ronak Patel Apr 20 at 10:42
  SPFieldUrlValue fieldUrl = new SPFieldUrlValue(item["Links"].ToString());
  url = fieldUrl.Url;
  string[] splittedValues = url.Split('=');
  string accountName =splittedValues[1].ToString();

  ServerContext ServerContext = ServerContext.GetContext(site);
  UserProfileManager profileManager = new UserProfileManager(ServerContext);
  UserProfile spUser = profileManager.GetUserProfile(accountName);
  IDictionaryEnumerator userProperties = spUser.GetEnumerator();

  string picture = spUser["PictureURL"].Value.ToString();
  row["Links"] = url;
  row["URL"] = picture;
share|improve this answer
Do you always have the user account on the url? Why split strings? If you want info on current user, wouldn't it be cheaper to just get user info from SPContext.Current.Web.CurrentUser? – Jorge Carvalho Oct 6 '11 at 0:40

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.