Thursday, June 2, 2011

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.
}
}

No comments:

Post a Comment