Tuesday 17 April 2012

Display SharePoint User Profile Picture - C#

SPWeb oWeb = currSite.OpenWeb();
SPList oList = oWeb.SiteUserInfoList;
SPListItem userInfo = oList.Items.GetItemById(SPContext.Current.Web.CurrentUser.ID);
imgPic.ImageUrl = userInfo["Picture"].ToString();

 

 

or

SPServiceContext context = SPServiceContext.GetContext(SPContext.Current.Site);
UserProfileManager profileManager = new UserProfileManager(context);
UserProfile theProfile = profileManager.GetUserProfile(SPContext.Current.Web.CurrentUser.LoginName);
//theProfile["PictureUrl"].Value = "<img url>";
litPic.Text = Convert.ToString(theProfile["Picture"]);
theProfile.Commit();
litPic.Text = "<img src=" + userLI["Picture"].ToString() + " />".ToString();

//userInfo.Update();

No comments:

Post a Comment