2

How do you get the user profile picture from an SPUser profile?

1
  • do you need some kind of permissions to get the pictures of other users than yourself? I only get my own picture. Feb 17, 2012 at 13:09

2 Answers 2

3

You can look at the User Information List, to grab the Picture column contents. It's a hidden field, so you might have to write a console app to get the columns, or find a reference somewhere online.

Tobias Zimmergren did a blog post on getting user data from the User Information List from an SPUser object: http://www.zimmergren.net/archive/2008/06/25/sharepoints-hidden-user-list-user-information-list.aspx

2

You can do something like this:

public string GetUserPicture(SPSite site)
{
    string userAccount = "domain\\account";

    ServerContext ctx = ServerContext.GetContext(site);
    UserProfileManager upm = new UserProfileManager(ctx);
    UserProfile up = upm.GetUserProfile(userAccount);

    return  up["PictureUrl"].Value;
}
1
  • 1
    tarjeieo : when user do not have change his profile picture that time it gives error. can we have some check on pictureUrl? Jul 11, 2014 at 13:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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