Undiscouraged
Undiscouraged

Reputation: 1125

How can I get the outlook contact's avatar image?

I am trying to get the contact's avatar image.

using Microsoft.Office.Interop.Outlook;

public sealed class OutlookAvatarFetcher
{
    private static void FetchAvatars()
    {
        var outlook = new Application();
        var folder = outlook.GetNamespace("MAPI").GetDefaultFolder(OlDefaultFolders.olFolderContacts);
        var items = folder.Items;

        for (var i = 0; i < items.Count; ++i)
        {
            var contact = items[i + 1] as ContactItem;
            if (contact == null)
                continue;


            if (contact.HasPicture)
            {
                // TODO store the picture somehow.
            }
        }
    }
}

But unfortunately I can't find a picture accessor.

Upvotes: 4

Views: 2972

Answers (2)

Dmitry Streblechenko
Dmitry Streblechenko

Reputation: 66306

Do you mean the picture that comes from Facebook or LinkedIn?

You cannot access it - MS did not provide any API to do that for legal purposes. Remember, that data comes from a third party service, and quite a few lawyers are involved in cases like this.

Upvotes: 0

Grant Winney
Grant Winney

Reputation: 66499

You can use the attachments property of the ContactItem:

contact.Attachments["ContactPicture.jpg"]

If you want to save the file to disk, for example, you could do something like this:

contact.Attachments["ContactPicture.jpg"].SaveAsFile(@"{some_path}\ContactPicture.jpg")

Upvotes: 4

Related Questions