Work With User Profiles Server Side And Client Side

Introduction

User profile is nothing but 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

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 UserProfileProperty of which you need a value.

  2. Client Side Object Model :

    Manager objects:

    SocialFollowingManager

    Primary namespace:

    Microsoft.SharePoint.Client.Social

    Class library:

    Microsoft.SharePoint.Client.UserProfiles.dll

    Please find the 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. }  
Ebook Download
View all
Learn
View all