This is another task that seemed to escape me for a long time. There is a list of Users (SPContext.Current.Web.Users) that we can access and look through but why aren’t their photos defined in this list?

Well it turns out there is another hidden list which maintains this info called SPContext.Current.Web.SiteUserInfoList. The trick to getting a users photo is quite simple, you just have to know to look for an attribute called “Picture”.


//Get the User Info List
SPList userInfoList = SPContext.Current.Web.SiteUserInfoList;
//Select a specific user
SPListItem userInfoListItem = userInfoList.GetItemById(userInfoId); //or other method
 
string imageUrl;
if (userInfoListItem["Picture"] != null)
{
    imageUrl = userInfoListItem["Picture"].ToString().TrimEnd(' ').TrimEnd(',');
}

Simple!

You may also like

Sharepoint Web Part Grouping

It has frustrated me that every web part that I develop is listed under Miscellaneous when we deploy it to production. I know this is a small thing but i believe it is important that these this are done correctly so that the company brand is recognized appropriately. Well i finally found the method to do it and have listed it here.

Keep Reading

"Capitalise" jquery extension

Sometimes there is a requirement to capitalise certain text input elements in web forms, i.e. to make just the first symbol uppercase when the user inputs details. This is often useful in fields like “first name”, “last name” etc. I thought I may share my implementation here with you and save you some precious time.

Keep Reading

Newsletter sign up

Every couple of months we send out an update on what's been happening around our office and the web. Sign up and see what you think. And of course, we never spam.