User profile photo - no photo from URL but can see photo in sharepoint. RRS feed

  • Question

  • Trying to figure this one out. I am tasked with writing some code to get a user's photo from Sharepoint so we can use it elsewhere. 

    My code works to get the photo using the employee's profile property for the photoURL. Problem is that when I do this, many photos come back as the no photo (the little person silhouette) but if I look at those people in SharePoint, office, and/or Skype they have a photo.

    I'm using C# and CSOM to do this. How do I get the photos? Is there another place to go get them that is more definitive over SharePoint tenant?

    Monday, June 5, 2017 7:55 PM

All replies

  • Hi,

    Are you using SharePoint online?

    If so, here is sample code for your reference:

    using (var clientContext = new ClientContext("https://xxx.sharepoint.com/sites/lee/"))
                    string password = "pw";
                    SecureString sec_pass = new SecureString();
                    Array.ForEach(password.ToArray(), sec_pass.AppendChar);
                    clientContext.Credentials = new SharePointOnlineCredentials("user@xxx.onmicrosoft.com", sec_pass);
                    // Get the people manager instance and load current properties
                    PeopleManager peopleManager = new PeopleManager(clientContext);
                    PersonProperties personProperties = peopleManager.GetMyProperties();                
                    clientContext.Load(personProperties, p => p.AccountName);
                    var pictureURL= peopleManager.GetUserProfilePropertyFor(personProperties.AccountName, "PictureURL");

    Here are some links for your reference.



    For SharePoint Online case, I would suggest you post in online forum, so it would not cause misunderstanding.


    Best Regards,


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Tuesday, June 6, 2017 3:11 AM
  • if you read my thing, I can get the photo but there isn't always a photo even if sharepoint has one..

    I've determined my problem is that MS doesn't sync the damn photos across AD, exchange, and sharepoint. so people have a photo but getting the URL from sharepoint doesn't mean sharepoint ever got it.

    Is there a way to get the photo using the Managed EWS API?

    Tuesday, June 6, 2017 12:36 PM
  • Hi,

    If you want to use EWS API to get user photo, you could check below thread.


    private static void GetContactPhoto(ExchangeService service, string ItemId)
       // Bind to an existing contact by using the ItemId passed into this function.
       Contact contact = Contact.Bind(service, ItemId);
       // Load the contact to get access to the collection of attachments.
       contact.Load(new PropertySet(ContactSchema.Attachments));
       // Loop through the attachments looking for a contact photo.
       foreach (Attachment attachment in contact.Attachments)
          if ((attachment as FileAttachment).IsContactPhoto)
             // Load the attachment to access the content.
       FileAttachment photo = contact.GetContactPictureAttachment();
       // Create a file stream and save the contact photo to your computer.
       using (FileStream file = new FileStream(photo.Name, FileMode.Create, System.IO.FileAccess.Write))

    Best Regards,


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    • Proposed as answer by Dennis Guo Thursday, June 15, 2017 9:31 AM
    Thursday, June 8, 2017 7:16 AM