4

How can I get profile image from spuser and also phone?

Guid fieldID1 = item.Fields.GetFieldByInternalName("User").Id;

string valueField1 = item[fieldID1].ToString();
SPFieldUserValue userField = (SPFieldUserValue)item.Fields[fieldID1].GetFieldValue(valueField1);
SPUser user = userField.User;

text1.Text = user.Name;
text2.Text = user.Email;

Right now my code gets name and email from the user

3 Answers 3

2

You could consider at least two options:

  1. retrieve an additional user properties from User Information List
  2. retrieve user properties via User Profile

Option 1

var userInfoList = site.RootWeb.SiteUserInfoList;
var userInfoItem = userInfoList.GetItemById(user.ID);
var pictureUrl = userInfoItem["Picture"];
var workPhone = userInfoItem["WorkPhone"];

Option 2

var serviceContext = SPServiceContext.GetContext(site);
var userProfileManager = new UserProfileTypedManager(serviceContext);
var userProfile = userProfileManager.GetUserProfile(user.LoginName);
var workPhone = userProfile["WorkPhone"].Value;
var picture = userProfile["PictureURL"].Value;
1
0

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


And You can also try to 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;
}

Also check these Links if they are helpful for you

1. 2. 3.

0

You can read Photo Url using User Profile Service API.

using (SPSite site = new SPSite("http://siteurl"))
{
    SPServiceContext context = SPServiceContext.GetContext(site);
    UserProfileManager profileManager = new UserProfileManager(context);
    UserProfile currentProfile = profileManager.GetUserProfile(user.LoginName);
    ProfileValueCollectionBase profileValueCollection = currentProfile.GetProfileValueCollection("PictureURL");
   //profileValueCollection.Value.ToString()
}
0

Your Answer

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

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