none
Get contact photo from EWS 2010 RRS feed

  • Question

  • Hello,

    I need help to get the contact photo of attendee from EWS API.  I am using .NET code.

    If you could suggest some help it will be great.

    1. tried the below code but results data is retrieving null.

    ContactsFolder folder = Folder.Bind(service, WellKnownFolderName.Contacts) as ContactsFolder;

                PropertySet props = new PropertySet(ContactSchema.Photo,

                                                    ContactSchema.HasPicture,

                                                    ContactSchema.DisplayName);

                ItemView view = new ItemView(200);

                view.PropertySet = props;

                FindItemsResults<Item> results = folder.FindItems(view);

                IEnumerable<Contact> contacts = results.Cast<Contact>();

                bool hasPic;

                foreach (Contact contact in contacts)

                {

                    if (contact.TryGetProperty(ContactSchema.HasPicture, out hasPic))

                    {

                        contact.Load(new PropertySet(ContactSchema.Attachments, ContactSchema.Photo)); // ContactSchema.Photo does nothing.

                        foreach (Attachment attachment in contact.Attachments)

                        {

                            if ((attachment as FileAttachment).IsContactPhoto)

                            {

                                attachment.Load();

                            }

                        }

                        // Only works once the attachment is loaded. This does not load attachment.

                        FileAttachment photo = contact.GetContactPictureAttachment();

                    }

                }

    2. I was trying the below code but need to understand how to get Item ID

    how to Get ItemID ?

    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.

                        attachment.Load();

                    }

                }

                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))

                {

                    photo.Load(file);

                }

            }

    Please suggest and looking for your response.

    Thanks.

    Regards,

    Guruprasad

    Wednesday, February 14, 2018 3:06 PM

All replies

  • It sounds like you might be trying to access the Contact Photo stored in Active Directory (as apposed to what is stored on a Contact which are two separate things) AD Contact photos aren't support in 2010  in EWS (support for this was added in Exchange 2013 using REST). If you need access to the Active directory stored picture then use  LDAP eg http://mohamedakb.blogspot.com.au/2012/05/retrieve-users-photo-from-active.html

    Cheers
    Glen


    Thursday, February 15, 2018 2:13 AM
  • Hi Glen,

    Thank you so much for your information.

    yes you are correct, we are trying to get the AD contact photo and using EWS 2010 version.  

    is there any chance to active from 2010 version only ?

    waiting for your reply.

    Thanks.

    Regards,

    Guruprasad

    Friday, February 16, 2018 11:53 AM
  • I am unable to access the below URL as it saying not exists that you shared. 

    http://mohamedakb.blogspot.co.uk/2012/05/retrieve-users-photo-from-active.htm

    Please confirm.

    Friday, February 16, 2018 11:55 AM
  • try https://adamprescott.net/2012/08/30/retrieve-active-directory-user-photos-in-c/

    Cheers
    Glen

    Monday, February 19, 2018 5:56 AM
  • Hi Glen,

    Thank you for the information.

    how to get the outlook attendee contact photo from EWS 2010. Please suggest.

    Thanks.

    regards, 

    Tuesday, February 20, 2018 11:41 AM