Sharepoint 2010 show the user profile picture programatically
SharePoint has a User Information list which can accessed using the object model.
So how do you get the profile picture? well i am posting a little code snippet which will make your life easier. It is in server object model though.
SPuser _user = SPcontext.current.web.CurrentUser;
using (SPSite Site = new SPSite(“Site URL”))
{
using (SPWeb Web = Site.OpenWeb())
{
SPList UserInfoList = Web.Lists["User Information List"];
SPListItem UserItem = UserInfoList.GetItemById(_user.ID);
UserItem["Picture"] = "Some url"; //-> here you can set or get the Picture property which is a url.
}
}
Related Post : Programmatically get user profile picture using Client Object model SharePoint 2010
So how do you get the profile picture? well i am posting a little code snippet which will make your life easier. It is in server object model though.
SPuser _user = SPcontext.current.web.CurrentUser;
using (SPSite Site = new SPSite(“Site URL”))
{
using (SPWeb Web = Site.OpenWeb())
{
SPList UserInfoList = Web.Lists["User Information List"];
SPListItem UserItem = UserInfoList.GetItemById(_user.ID);
UserItem["Picture"] = "Some url"; //-> here you can set or get the Picture property which is a url.
}
}
Related Post : Programmatically get user profile picture using Client Object model SharePoint 2010
public static string GetUserProfilePictureURL(string username)
ReplyDelete{
string Url = string.Empty;
SPServiceContext serviceContext = SPServiceContext.GetContext(SPContext.Current.Site);
UserProfileManager upm = new UserProfileManager(serviceContext);
if (upm.UserExists(username))
{
UserProfile profile = upm.GetUserProfile(username);
if (profile != null)
{
Url = profile["PictureURL"].Value.ToString();
}
}
//change it to the default if the user does not have an image specified
if (string.IsNullOrEmpty(Url))
Url = "/_layouts/images/unknown.png";
return Url;
}
can we get image url by using employee id??
Delete