login user image in the SP site

Hi,

I need to display login user image in the site , I have checked in google , I found some examples with the code . can I get this functionality via OOB, like it is coming in the SharePoint MySite .

Any ideas?

Thanks
August 22nd, 2015 7:48am

Hi Nikhil,

Kindly elaborate your requirement. Where do you want to show the Profile Image. There are multiple ways to show the profile image, whether it will be through Content Query / Custom Content Editor. Kindly explain where it has to be shown.

Free Windows Admin Tool Kit Click here and download it now
August 24th, 2015 1:38am

Thanks for your response.

I need to add the Image in the landing page of the site.

August 24th, 2015 8:32am

I am assuming you need to get it using client side.

For server side,

using (SPSite currentSite = new SPSite(SPContext.Current.Site.ID)) { using (SPWeb rootWeb = currentSite.OpenWeb()) { try { string userLoginName = rootWeb.CurrentUser.LoginName; SPServiceContext serviceContext = SPServiceContext.GetContext(currentSite); UserProfileManager upm = new UserProfileManager(serviceContext); UserProfile user = upm.GetUserProfile(userLoginName); string userProfilePictureUrl = user[PropertyConstants.PictureUrl].ToString();

//The URL which you get from above could be bound to any image control. } catch (Exception) { } } }

Now for if you need to have the same functionality in client side, use the following,

You can use the below endpoint 

Below snippet for getting Login Name

http://siteurl/_api/web/GetUserById(<AuthorID>)/LoginName

Then use the below URL for getting the profile image.

http://siteurl/_api/SP.UserProfiles.PeopleManager/GetPropertiesFor(accountName=@v)?@v='<LoginName>'&$select=PictureUrl

For more information on using REST API, refer the below URL.

Vardhman's Blog for User profile

Free Windows Admin Tool Kit Click here and download it now
August 26th, 2015 9:38am

Thanks for the details provided,  am able to get the profile picture with rest API but when I try to open the page for the first time in the new browser it is asking me the user id and password for connecting to MySite , is there  any way to get rid of this ?

Any  idea

August 27th, 2015 7:50am

Hi Nikhil,

This may happen if you are accessing the mysite application which is not there in your domain. Basically, if you add your application to your safe sites, this prompting will not happen. Make sure your User authentication is set as "Automatic Logon only in Intranet Zones" in security settings. Refer the screenshot below. 

IE Security Settings - Automatic Login

You can also refer the below link for your reference.

MSDN Link for Login Prompt

Free Windows Admin Tool Kit Click here and download it now
August 30th, 2015 1:26am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics