In this article I am going to explain how we can get
the current login user's information by using CSOM in SharePoint 2013. In
SharePoint it's little bit hard to get info by using client side object model.
But in SharePoint 2013 by using Microsoft.SharePoint.Client.UserProfiles;
it's become easy.
Now see this by making a program...
Below is my code:
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 GetUserInformation
{
class Program
{
static void Main(string[] args)
{
string siteURL = "http://localhost:1000/";
ClientContext clientContext = new
ClientContext(siteURL);
PeopleManager
peopleManager = new PeopleManager(clientContext);
PersonProperties
personProperties = peopleManager.GetMyProperties();
clientContext.Load(personProperties, p => p.AccountName, p =>
p.Email, p => p.DisplayName);
clientContext.ExecuteQuery();
StringBuilder sbUser = string.Empty;
sbUser += "User's Account :" +
personProperties.AccountName + System.Environment.NewLine;
sbUser += "Email: " + personProperties.Email +
System.Environment.NewLine;
sbUser += "Display Name: " +
personProperties.DisplayName + System.Environment.NewLine;
}
}
}