Using UserPhoto.ASPX to get picture from User Profile Store

As you may know the User Profile Picture is stored in My Site Host site collection. The User Profile property PictureURL store the location of the picture. But the problem I ran in to is cross domain issue in the SharePoint Hosted App. The app was located in the app domain and the PictureURL points to my-host site collection.
https://{your tenant}
I used the following blog reference to solve the issue.
User profile picture in SP hosted app
So why I am still blogging, because still ran in to issue with the account name passed in the query string. I spent some time to figure out I thought it can be useful to someone.
The AccountName user profile property was (999999 is to scrub the data)
AccountName = i:0#.f|membership|999999@{your tenant}.com
Passing the account name as the above sting will create an issue and will not return your image.
You will need to encode the AccountName value. As shown below.
var accountName = encodeURIComponent(

var qsSPHostUrl = getQueryStringParameter(‘SPHostUrl’);

var picUrl = decodeURIComponent(
qsSPHostUrl +
“/” +
_spPageContextInfo.layoutsUrl +
+ accountName ;
// Finally apply the src attribute with the value.
$get(“imgUserPhoto”).src = picUrl;

The value in the SRC attribute will be as following. Your picture should show up.
https://{your tenant}{your tenant}.com

About Pankaj

I am a Developer and my linked profile is
This entry was posted in SharePoint, SharePoint 2013, Uncategorized and tagged . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s