How to set Profile Picture in Office 365 SharePoint 2013 site using CSOM

Home | SharePoint 2013 | How to set Profile Picture in Office 365 SharePoint 2013 site using CSOM

Step1

Create a console application in Visual Studio 2013.

Step2

Import the following namespaces

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.SharePoint.Client;
using Microsoft.SharePoint.Client.UserProfiles;

using System.Net;
using System.Security;
using System.Globalization; 

Step3

Add the following references

Step4

            Uri oUri = new Uri("https://yoursite.sharepoint.com");

            Office365ClaimsHelper claimsHelper = new Office365ClaimsHelper(oUri, "youruserid@yoursite.onmicrosoft.com", "password");
            using (ClientContext oClientContext = new ClientContext(oUri))
            {
                oClientContext.ExecutingWebRequest += claimsHelper.clientContext_ExecutingWebRequest;
                PeopleManager oPeopleManager = new PeopleManager(oClientContext);
                
                Stream oStream = new FileStream(@"C:MyPhotoSundar.jpg", FileMode.Open);
                oPeopleManager.SetMyProfilePicture(oStream);
                oClientContext.ExecuteQuery();
                Console.Write("Profile picture is set");



                Console.ReadLine();
            }

3 thoughts on “How to set Profile Picture in Office 365 SharePoint 2013 site using CSOM

Leave a Reply