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:
- Server Side Object Model
- Client side object model
Information
- 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.
- 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.
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using Microsoft.SharePoint.Client;
- using Microsoft.SharePoint.Client.UserProfiles;
-
- namespace WorkOnUserProfile
- {
- public class Program
- {
- public static void Main(string[] args)
- {
- const string siteURL = "http://<SharePointSiteURL>";
- const string accountName = "<Account Name> E.g. Global\BhalsingKetak";
-
- ClientContext clientContext = new ClientContext(siteURL);
-
- PeopleManager peopleManager = new PeopleManager(clientContext);
- PersonProperties personProp = peopleManager.GetPropertiesFor (accountName);
-
- clientContext.Load(personProp, p => p.AccountName, p => p.UserProfileProperties);
- clientContext.ExecuteQuery();
-
- foreach (var property in personProp.UserProfileProperties)
- {
- Console.WriteLine(string.Format("{0}: {1}",
- property.Key.ToString(), property.Value.ToString()));
- }
- Console.ReadKey();
- }
- }
- }