Hi,
I have created one page for update user profile fields like Name,Department,Designation,Image By HR .Here how to update other user Profile Picture Programmatically?
Please assist me on this
Technology Tips and News
Hi,
I have created one page for update user profile fields like Name,Department,Designation,Image By HR .Here how to update other user Profile Picture Programmatically?
Please assist me on this
Hope it helps you
https://social.technet.microsoft.com/Forums/en-US/2d676105-38e1-41ab-9f63-ad9737f65453/update-picture-for-a-user-using-powershell
For update User's Picture in user profile, you have to get first particular User's Profile and then modify "Picture Url" property of the user.
As per below PS command.
[Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") [Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server") $siteurl = "http://<MySiteHost URL>/" $site = New-Object Microsoft.SharePoint.SPSite($siteurl) $context = [Microsoft.Office.Server.ServerContext]::GetContext($site) #This gets the User Profile Manager which is what we want to get hold of the users $upm = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($context) $user = "DOMAIN\username" #Put it in a loop for iterating for all users if ($upm.UserExists($user)) { $profile = $upm.GetUserProfile($user) $profile["PictureURL"].Value = "<MySiteHostURL>/User%20Photos/Profile%20Pictures/user.jpg"; $profile.Commit(); } $site.Dispose()
Hi,
i want to do Programmatically instead of powershell.HR Person going to update others profile image.
Plz assist me..i tried with server side scripting but its not working
You can impose this powershell script into your code.
https://www.google.co.in/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&uact=8&ved=0CB0QFjAA&url=https%3A%2F%2Fsamlman.wordpress.com%2F2015%2F03%2F01%2Fusing-powershell-for-sharepoint-2010-in-c%2F&ei=dFaKVYirJ9WGuASZo7igBg&usg=AFQjCNGZJoWG_Ycy0nmpEp7EdFGPzgh_Eg&bvm=bv.96339352,d.c2E
Hi,
You can use UserProfileManager class to update user profile fields programmatically.
Here is a code snippet for your reference:
using Microsoft.Office.Server; using Microsoft.Office.Server.UserProfiles; using (SPSite site = new SPSite("http://sitecollectionurl")) { //User profile manager object holds the complete profile store UserProfileManager profileManager = new UserProfileManager(ServerContext.GetContext(site)); //UserProfile object holds the acount specific userprofile UserProfile userProfile = profileManager.GetUserProfile("domain\\administrator"); //OTB property name can be assigned as below using PropertyConstants class userProfile[PropertyConstants.FirstName].Value = "My first name"; //Custom property value can be assigned as below by hardcoding the property name userProfile["CustomPropertyName"].Value = "Test Value"; userProfile.Commit(); }
About how to update user profile picture, you can refer the article below:
Update User Profile picture programmatically in SharePoint
Thanks
Best Regards
Because the normal user won't have rights to do this, you'll have to run the code elevated.
SPSecurity.RunWithElevatedPrivileges(delegate() { // add your code here });
Then make sure that the account used for the identity of the mysite app pool has rights to the user profile service.