SharePoint user profile properties read / Modify using object model

SharePoint user profile properties read / Modify using object model

//Updates a user profile
//Creates a user profile. Obtains the property values from the default
//domain controller or the master connection that is configured on the
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint.Administration;
using Microsoft.Office.Server.UserProfiles;
using Microsoft.SharePoint;
using Microsoft.Office.Server;
using System.Web;

namespace UserProfilesApp
    class Program
        static void Main(string[] args)
                using (SPSite site = new SPSite("http://servername"))
                    SPServiceContext context = SPServiceContext.GetContext(site);
                    UserProfileManager profileManager = new UserProfileManager(context);
                    string sAccount = "domainname\\username";
                    UserProfile u = profileManager.GetUserProfile(sAccount);
                    u[PropertyConstants.HomePhone].Value = "nnnnnnnnnn";
                    u[PropertyConstants.CellPhone].Value = "nnnnnnnnnn";

            catch (UserNotFoundException exception)



function getUserProfile(userID)
var clientContext = new SP.ClientContext.get_current();
var web = clientContext.get_web();
var userInfoList = web.get_siteUserInfoList();
var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml(‘<View><Query><Where><Eq><FieldRef Name=\’ID\’/>’ +’<Value Type=\’Number\’>’ + userID + ‘</Value></Eq>’ +
this.collListItem = userInfoList.getItems(camlQuery);
clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded),Function.createDelegate(this, this.onQueryFailed));
function onQuerySucceeded(sender, args)
var item = collListItem.itemAt(0);
var profile = item.get_item(‘Notes’);
var pictureUrl = item.get_item(‘Picture’).get_url();
var userImage = document.getElementById(‘myImageContainer’); -> Image object
userImage.src = pictureUrl;
var profileDiv = document.getElementById(‘userProfileContainer’);
profileDiv.innerHTML = profile;


About sharepointsriram

9+ Yrs of IT experience
This entry was posted in Sharepoint 2010 User Profiles. 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 )

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