locked
Retrieving contact picture with EWS Managed API RRS feed

  • Question

  • Hello, I'm trying retrieve the contact picture that's stored within a contact if the "HasPicture" property is set.  I can't seem to find any examples on how to do this.

    Environment is Exchange 2010, and using EWS Managed API.

    Any help would be appreciated.

    Friday, April 8, 2011 9:44 PM

Answers

  • The contact photo is just held in an attachment on the contact where IsContactPhoto photo is set to true eg to download the contact photo from a contact

              Contact cnContact = (Contact)cnItem;
              if (cnContact.HasPicture == true) {
                cnContact.Load();
                foreach (Attachment attachment in cnContact.Attachments) {
                  if (attachment is FileAttachment)
                  {
                    FileAttachment fileAttachment = attachment as FileAttachment;
                    if (fileAttachment.IsContactPhoto == true)
                    {
                      // Load the file attachment into memory and print out its file name.
                      fileAttachment.Load();
                      Console.WriteLine("Attachment name: " + fileAttachment.Name);
    
                      // Load attachment contents into a file.
                      fileAttachment.Load("C:\\temp\\" + fileAttachment.Name);
    
                      // Stream attachment contents into a file.
                      FileStream theStream = new FileStream("C:\\temp\\Stream_" + fileAttachment.Name, FileMode.OpenOrCreate, FileAccess.ReadWrite);
                      fileAttachment.Load(theStream);
                      theStream.Close();
                      theStream.Dispose();
                    }
                  }
                }
              }
    
    Cheers
    Glen
    • Marked as answer by Blocko Tuesday, April 12, 2011 8:08 PM
    Monday, April 11, 2011 2:20 AM