Wednesday, February 10, 2016

How to retrieve user profile picture from user's My Site using SharePoint REST API

Social networking sites, personalization aesthetics and increased user interactions and expectations has changed the way website and portals are developed. 

One of the requirement often comes to SharePoint developers is to show user's profile picture on site/portal's home page or preferably in the site's header. SharePoint stores user related information in user's My Site but fetching the information from My Site and displaying it on other portal's pages could be a challenge. 

SharePoint REST API allows us to easily fetch all user profile related information and display it anywhere we want in the sharepoint portal. 

Below code snippet fetches the user's profile pic URL from user profile properties and assign it to a hyperlink tag on the page.

html to display profile pic as a background of a hyperlink.

Profile.js Javascript code to fetch profile pic url using Rest API and JQuery.

Monday, February 1, 2016

Programatically assign value to a 'Hyperlink or Picture Type' column in a SharePoint 2016 List

Recently I had a requirement to collect publishing pages URLs in a SharePoint 2016 List. Adding an item in a list is straight forward and that's probably the first development task every SharePoint developer does.

But I was not able to find enough resources on adding a 'HyperLink or Picture Type' column in an SPList.

Below is the code snippet to assign value to a hyper link column.

Hyper link column expects value in <ABSOLUTE URL>, <TITLE> format.

Important thing to note here is that hyperlink should always start with 'http://'. If you try to assign a relative URL or a URL which starts with 'www', you will always get SPFieldValidationException.

Hope it will help.