Open Program.cs file and replace the code with the following:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.SharePoint.Client;
using Microsoft.SharePoint.Client.UserProfiles;
namespace UserProfileService
{
class Program
{
static void Main(string[] args)
{
//// String Variable to store the siteURL
string siteURL = "http://c4968397007:3695/";
//// String Variable to store the account name
string accountName ="Pai";
//// To get the context of the SharePoint site to access the data
ClientContext clientContext = new ClientContext(siteURL);
//// PeopleManager class provides the methods for operations related to people
PeopleManager peopleManager = new PeopleManager(clientContext);
//// PersonProperties class is used to represent the user properties
//// GetPropertiesFor method is used to get the user properties for a particular user
PersonProperties personProperties = peopleManager.GetPropertiesFor(accountName);
clientContext.Load(personProperties, p => p.AccountName, p => p.Email, p => p.DisplayName);
clientContext.ExecuteQuery();
//// Display the user profile properties - AccountName, Email, DisplayName
Console.WriteLine("Account Name: " + personProperties.AccountName);
Console.WriteLine("Email: " + personProperties.Email);
Console.WriteLine("Display Name: " + personProperties.DisplayName);
Console.ReadLine();
}
}
}