Skip to content

Instantly share code, notes, and snippets.

@princeppy
Forked from vman/SetUserImage.cs
Created July 18, 2018 13:40
Show Gist options
  • Select an option

  • Save princeppy/64e8d77d1613b6e8be1ac7ff6db7a92e to your computer and use it in GitHub Desktop.

Select an option

Save princeppy/64e8d77d1613b6e8be1ac7ff6db7a92e to your computer and use it in GitHub Desktop.
using Microsoft.SharePoint.Client;
using Microsoft.SharePoint.Client.UserProfiles;
using System;
using System.IO;
using System.Security;
namespace ImgSetter
{
class Program
{
static void Main(string[] args)
{
using (ClientContext clientContext = new ClientContext("https://yoursite.sharepoint.com/"))
{
SecureString passWord = new SecureString();
foreach (char c in "yourpassword".ToCharArray()) passWord.AppendChar(c);
clientContext.Credentials = new SharePointOnlineCredentials("[email protected]", passWord);
var peopleManager = new PeopleManager(clientContext);
System.IO.Stream stream = new FileStream(@"C:\imgToSetAsProfilePic.jpg",FileMode.Open);
peopleManager.SetMyProfilePicture(stream);
clientContext.ExecuteQuery();
Console.WriteLine("Profile Picture Set");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment