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?
ThanksTechnology Tips and News
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?
ThanksHi 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.
Thanks for your response.
I need to add the Image in the landing page of the site.
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.
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
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.
You can also refer the below link for your reference.