How to retrieve current user in SharePoint 2013 Online using CSOM

In this post, we’ll see how we can retrieve the current user in a SharePoint 2013 online site using client side object model (CSOM). We’ll  be using a console application for the purpose of this demonstration.

Open Visual Studio 2013

File –> New Project –> C# –> Console application

Add  reference to the following assemblies.



Import the following namespaces at the top of Program.cs

using  Microsoft.SharePoint.Client;
using System.Security;

namespace Retrievecurrentuser
    class Program
        static void Main(string[] args)

            using (ClientContext oClientContext = new ClientContext(@""))

                //Assign User Id for your SharePoint Online tenant     
                string UserName = "";

                //Assign password for your SharePoint online tenant
                string Password = "password";

                //Create a SecureString object from password string, needed for SharePointOnlineCredentials class
                SecureString SecurePassword = GetSecureString(Password);
                oClientContext.Credentials = new SharePointOnlineCredentials(UserName, SecurePassword);

                //load the properties of web object
                Web oWeb = oClientContext.Web;

                //retrieve the site name
                string SiteName = oWeb.Title;

                //retrieve the current user

            Console.WriteLine("Login Name"+ oClientContext.Web.CurrentUser.LoginName);
                Console.WriteLine("Is Admin"+ oClientContext.Web.CurrentUser.IsSiteAdmin);
                Console.WriteLine("Email"+ oClientContext.Web.CurrentUser.Email);


        private static SecureString GetSecureString(String Password)
            SecureString oSecurePassword = new SecureString();

            foreach (Char c in Password.ToCharArray())

            return oSecurePassword;


Then create a clientcontext in the program.cs, load the web object (execute query) and then load the current user based on the web object.

Now we’ll be able to fetch the user properties like the below.


 Subscribe to my blog

Leave a Reply