C# la Outlook’taki kişilerin resimlerine ulaşın

Tem 02 2011 Published by under c#

Outlook’taki  kişilerin resimlerini görmek ve ListView’in içine doldurmak için;

using Outlook = Microsoft.Office.Interop.Outlook;
Outlook._Application outobj;
Outlook.MAPIFolder fldContacts;
Microsoft.Office.Interop.Outlook.ContactItem contact;
listView2.Clear();
            ımageList2.Images.Clear();
            outobj = new Outlook.Application();
            fldContacts = (Outlook.MAPIFolder)outobj.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts);
            int sira2 = 0;

            listView2.LargeImageList = ımageList2;
            foreach (Outlook._ContactItem kontakt in fldContacts.Items)
            {
                if (kontakt.HasPicture)
                {
                    contact = (Microsoft.Office.Interop.Outlook.ContactItem)kontakt;
                    ımageList2.Images.Add(sira2.ToString(), Image.FromFile(GetContactPicturePath(contact)));

                }
                listView2.Items.Add(new ListViewItem(kontakt.FullName, sira2.ToString()));
                sira2 = sira2 + 1;
            }
public static string GetContactPicturePath(Microsoft.Office.Interop.Outlook.ContactItem contact)
        {
            return GetContactPicturePath(contact, System.IO.Path.GetTempPath());
        }

        public static string GetContactPicturePath(Microsoft.Office.Interop.Outlook.ContactItem contact, string path)
        {
            string picturePath = "";
            if (contact.HasPicture)
            {
                foreach (Microsoft.Office.Interop.Outlook.Attachment att in contact.Attachments)
                {
                    if (att.DisplayName == "ContactPicture.jpg")
                    {
                        try
                        {
                            picturePath = System.IO.Path.GetDirectoryName(path) + "\\Contact_" + contact.EntryID + ".jpg";
                            if (!System.IO.File.Exists(picturePath))
                                att.SaveAsFile(picturePath);
                        }
                        catch
                        {
                            picturePath = "";
                        }
                    }
                }
            }
            return picturePath;
        }

not:kodlar 2010 ve öncesine aittir, yeni yöntemler çıkmış olabilir.

One response so far

Bir Cevap Yazın