I need to fetch some properties. How can I access User Profile with Client Object Model?

Any code example will be helpful.

  • client object model - need to be specific in usage: ECMA/JS or .NET (or REST) ? Jun 4, 2014 at 14:20

4 Answers 4


PowerShell would be another way that's fast as well using the following steps:

  1. Get the User Profile from the SP Site (given the login name)
  2. Get all the properties from the UserProfile 'object'
  3. Get/Set individual property of the UserProfile.

See these two posts for the PowerShell Code (both are similar) -

A Quick Guide to Getting, Setting and Copying User Profile Properties using PowerShell.

SharePoint: Get Set and Copy User Profile Properties using PowerShell.

A listing of SharePoint PowerShell cmdlets at the Microsoft TechNet site - Use Windows PowerShell cmdlets to configure the User Profile service in SharePoint Server 2013.

[UPDATED: May 4th 2014]

Using PowerShell with REST has its benefits in flexibility and faster development -

Invoke-RestMethod for the Rest of Us

More about the Invoke-RestMethod (REST calls in PowerShell)

PowerShell can then be used with SharePoint 2013: Get UserProfile Properties with REST API

  • He specifically asked for CSOM. Jun 4, 2014 at 11:29
  • I had interpreted as using the .NET Client Object Model in the original question. I have updated above response with using PowerShell and REST API calls. Jun 4, 2014 at 14:11
  • Ahh, good point. Had not considered .Net. Jun 4, 2014 at 15:44

This example uses the User Profiles object model to display the user profile properties that exist on the server. Replace servername with an actual value before running the code example. Also add references to the following in your Microsoft Visual Studio project:

  • Microsoft.Office.Server
  • Microsoft.Office.Server.UserProfiles
  • Microsoft.SharePoint
  • System.Web

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

    namespace UserProfilesApp { class Program { static void Main(string[] args) {

            using (SPSite site = new SPSite("http://servername"))
                  SPServiceContext context = 
                  ProfileSubtypeManager psm = ProfileSubtypeManager.Get(context);
                  ProfileSubtype ps = psm.GetProfileSubtype(ProfileSubtypeManager.GetDefaultProfileName(ProfileType.User));
                //Get the properties
                  ProfileSubtypePropertyManager pspm = ps.Properties;
                    foreach (ProfileSubtypeProperty profileSubtypeProperty in pspm.PropertiesWithSection )

Here are other references:

How to: Retrieve a User Profile

How to: Retrieve User Profile Properties

How to: Retrieve What's Common Between Two User Profiles

How to: Get Recent User Profile Changes Using the Change Log

  • I need to fetch these properties in client object model...using ECMA script, to be specific first of all I want to access current logged in user and then its respective properties.
    – Rajeev K
    Jun 4, 2014 at 3:03
  • what kind of properties you want to fetch? Also which version of SharePoint are you using? Jun 5, 2014 at 7:06

For JavaScript you can do something like:

var personProperties;

// Ensure that the SP.UserProfiles.js file is loaded before the custom code runs.
SP.SOD.executeOrDelayUntilScriptLoaded(getUserProperties, 'SP.UserProfiles.js');

function getUserProperties() {

// Replace the placeholder value with the target user's credentials.
var targetUser = "domainName\\userName";

// Get the current client context and PeopleManager instance.
var clientContext = new SP.ClientContext.get_current();
var peopleManager = new SP.UserProfiles.PeopleManager(clientContext);

// Get user properties for the target user.
// To get the PersonProperties object for the current user, use the
// getMyProperties method.
personProperties = peopleManager.getPropertiesFor(targetUser);

// Load the PersonProperties object and send the request.
clientContext.executeQueryAsync(onRequestSuccess, onRequestFail);

// This function runs if the executeQueryAsync call succeeds.
function onRequestSuccess() {
// Get a property directly from the PersonProperties object.
var messageText = " \"DisplayName\" property is "
    + personProperties.get_displayName();

// Get a property from the UserProfileProperties property.
messageText += "<br />\"Department\" property is "
    + personProperties.get_userProfileProperties()['Department'];
$get("results").innerHTML = messageText;

// This function runs if the executeQueryAsync call fails.
function onRequestFail(sender, args) {
    $get("results").innerHTML = "Error: " + args.get_message();

using Client Object Model

Solution Explorer, right-click on the "References" folder and then click on "Add Reference"

We have to add ddl:

> Microsoft.SharePoint.Client.dll
> Microsoft.SharePoint.Client.Runtime.dll
> Microsoft.SharePoint.Client.UserProfiles.dll


using Microsoft.SharePoint.Client;
using Microsoft.SharePoint.Client.UserProfiles;


string siteUserName="nam";
string _siteurl="http://sharepoint.com";
string _sitepassword ="pass@word1";
string accountName ="raghupc\raghu";
ClientContext clientContext = new ClientContext(_siteurl);
clientContext.AuthenticationMode =ClientAuthenticationMode.Default;
clientContext.Credentials = new System.Net.NetworkCredential(_siteUserName, _sitepassword, _domainName);
Web oweb = clientContext.Web;
PeopleManager peopleMang = new PeopleManager(clientContext);
PersonProperties personProp = peopleMang.GetPropertiesFor(accountName);
clientContext.Load(personProp, p => p.AccountName, p => p.Email, p => p.DisplayName);
Label1.Text= personProp.AccountName;
Label2.Text= personProp.Email;
Label3.Text =personProp.DisplayName;

Click Here .You will see more details

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.