SharePoint: Working with User Profile with Different APIs

Introduction

User profile is nothing put an information object where all the user related information is stored. User profiles and user profile properties provide information about SharePoint users. SharePoint 2013 provides number of APIs that we can use to programmatically work with user profiles:

  1. Server Side Object Model
  2. Client side object model
  3. JavaScript object model
  4. Representational State Transfer Service

Information

  1. Server Side object Model:

    • Manager objects: UserProfileManager, PeopleManager.
    • Primary namespace: Microsoft.Office.Server.UserProfiles.
    • Class library: Microsoft.Office.Server.UserProfiles.dll

    For more information on how to extract a user profile property please find this blog of mine where you just need to pass the User Profile Property of which you need a value: Helper Method to Extract a Value from User Profile Service Application.

  2. Client Side Object Model:

    • Manager objects: SocialFollowingManager.
    • Primary namespace: Microsoft.SharePoint.Client.Social.
    • Class library: Microsoft.SharePoint.Client.UserProfiles.dll

Please find below console application to work with User Profile using .net client object model.

  1.  using System;   
  2.  using System.Collections.Generic;   
  3.  using System.Linq;   
  4.  using System.Text;   
  5.  using Microsoft.SharePoint.Client;   
  6.  using Microsoft.SharePoint.Client.UserProfiles;   
  7.    
  8.  namespace WorkOnUserProfile   
  9.  {   
  10.     public class Program   
  11.     {   
  12.        public static void Main(string[] args)   
  13.        {   
  14.           const string siteURL = "http://<SharePointSiteURL>";   
  15.           const string accountName = "<Account Name> E.g. Global\BhalsingKetak";   
  16.    
  17.           ClientContext clientContext = new ClientContext(siteURL);   
  18.    
  19.           PeopleManager peopleManager = new PeopleManager(clientContext);   
  20.           PersonProperties personProp = peopleManager.GetPropertiesFor (accountName);   
  21.    
  22.           clientContext.Load(personProp, p => p.AccountName, p => p.UserProfileProperties);   
  23.           clientContext.ExecuteQuery();   
  24.    
  25.           foreach (var property in personProp.UserProfileProperties)   
  26.           {   
  27.              Console.WriteLine(string.Format("{0}: {1}",   
  28.              property.Key.ToString(), property.Value.ToString()));   
  29.           }   
  30.           Console.ReadKey();   
  31.        }   
  32.     }   
  33.  }   
Reference

Follow people in SharePoint 2013

Happy SharePointing!!!!