Get Profile picture url from User Information List using SharePoint 2013 server object model

In this post, we will discuss how we can get profile picture url from User Information List using SharePoint 2013 server object model. User Information List is a hidden list maintains by SharePoint which contains one entry for every user who accessed the site collection or explicit access has been given to any particular user. This list contains basic information like About me, Picture url, Name, Title, Department etc.

If SharePoint farm is using User Profile Application, then these User Information List fields will not be editable rather it will redirect to My Site Host. If your SharePoint farm is not using User Profile Application, the user can be able to edit the User Information List fields.

Also, you may need to check:
SharePoint 2013 SPListItem method Update SystemUpdate and UpdateOverwriteVersion

Export SharePoint 2013 List Items to Word Document using SharePoint Server Side Object Model

Get SharePoint Features using PowerShell in SharePoint 2013

Here in this example, we will try to retrieve the user profile picture url from User Information List using the Server object model.

Below is the full code.

try

{

string LoginName = string.Empty;

string SiteUrl = SPContext.Current.Site.Url;

string Username = SPContext.Current.Web.CurrentUser.LoginName;

SPSite Site = new SPSite(SiteUrl);

string pictureUrl = string.Empty;

using (SPWeb Web = Site.OpenWeb())
{

SPList List = Web.Lists[“User Information List”];

SPQuery Query = new SPQuery();

Query.Query = “<Where><Eq><FieldRef Name = ‘ID’/><Value Type=’Text’>”+Username+”</Value></Eq></Where>”;

SPListItemCollection ItemCollection;

ItemCollection = List.GetItems(Query);

if (ItemCollection.Count > 0)
{
foreach(SPListItem ListItem in ItemCollection)
{
if(ListItem[“Picture”] != null)
{
pictureUrl = ListItem[“Picture”].ToString();
}

}

}

}
}


catch(Exception ex)
{
}

Hope this will be helpful.


You May Also like the Following SharePoint Online Tutorials:

About Bijay Kumar

I am Bijay from Odisha, India. Currently working in my own venture TSInfo Technologies in Bangalore, India. I am Microsoft Office Servers and Services (SharePoint) MVP (5 times). I works in SharePoint 2016/2013/2010, SharePoint Online Office 365 etc. Check out My MVP Profile.. I also run popular SharePoint web site SharePointSky.com

View all posts by Bijay Kumar →