Email: Password:       Forgot Password 
    .netCodeSG
A Saarsha Group Online Community for dot net codes group like C#, Asp.NET, VB.NET, Sharepoint, JavaScript, JQuery, Ajax, SQL, WCF, WPF.
 
TECHNOLOGIES:
 

SharePoint 2013 - Get the Current User Information Using CSOM

Article:
Viewed:  5056 
Posted On:  11/07/2013 11:08:16 
How to Get Current User's Information in SharePoint 2013...? 

 

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; 
        }
    }
}

  Comment:
         HOME   |   Submit Article   |   Contact Us   |   About Us   |   Terms & Condition   |   Advertise With us