Created
August 11, 2014 06:09
-
-
Save chakkaradeep/0696f966aa376a857f8e to your computer and use it in GitHub Desktop.
Office 365 API Contacts - Get Contact Picture
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static async Task<byte[]> GetContactImage(string strContactId) | |
{ | |
byte[] bytesContactPhoto = new byte[0]; | |
//query the contact by contact Id | |
//GetById is broken so you need to use this instead | |
var contact = await _exchangeClient.Me.Contacts[strContactId].ExecuteAsync(); | |
if (contact != null) | |
{ | |
//get the attachments | |
var attachmentResult = await ((IContactFetcher)contact).Attachments.ExecuteAsync(); | |
var attachments = attachmentResult.CurrentPage.ToArray(); | |
//find the attachment entity that is a contact photo | |
var contactPhotoAttachment = attachments.OfType<IFileAttachment>().FirstOrDefault(a => a.IsContactPhoto); | |
if (contactPhotoAttachment != null) | |
{ | |
//read the photo bytes | |
bytesContactPhoto = contactPhotoAttachment.ContentBytes; | |
} | |
} | |
return bytesContactPhoto; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment