Skip to content

Instantly share code, notes, and snippets.

@chakkaradeep
Created August 11, 2014 06:09
Show Gist options
  • Save chakkaradeep/0696f966aa376a857f8e to your computer and use it in GitHub Desktop.
Save chakkaradeep/0696f966aa376a857f8e to your computer and use it in GitHub Desktop.
Office 365 API Contacts - Get Contact Picture
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