SharePoint – Change User Profile Picture for Single

Posted: April 28, 2016 in Uncategorized
Tags: , , , , , , ,

In this post I will show how to change User Profile Picture for Single .

Using Console Application in Visual Studio .Net, I deploy and change picture based on User ID (as custom column in CA from AD):

For Single User:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Office.Server;
using Microsoft.Office.Server.UserProfiles;
using Microsoft.SharePoint;

namespace UserProfilePicURL_SUser
{
class Program
{
static void Main(string[] args)
{
using (SPSite site = new SPSite(“SiteURL”))
{
SPServiceContext context = SPServiceContext.GetContext(site);
UserProfileManager myUserProfileManager = new UserProfileManager(context);
UserProfile aUser = myUserProfileManager.GetUserProfile(“Domain\\UserAccount”);
try
{

string origUrl = (string)aUser[PropertyConstants.PictureUrl].Value;
string displayName = (string)aUser[PropertyConstants.AccountName].Value;
string hUID = (string)aUser[“UserID”].Value;

string newUrl2 = “PictureURL/UserID.jpg”;
aUser[PropertyConstants.PictureUrl].Value = newUrl2.ToString();
aUser.Commit();
Console.WriteLine(“Account Name: ” + displayName.ToString());
Console.WriteLine(“Image URL: ” + newUrl2.ToString());
Console.WriteLine(“User ID Account: ” + hUID.ToString());
Console.Read();

}
catch (System.Exception ex)
{
Console.WriteLine(ex.Message);}}}}}

Happy SharePoint

Advertisements

Leave a Reply

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

WordPress.com Logo

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

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s