C # VSTO Outlook 2007: how to show a contact using EntryID

How to open a contact using C # VSTO Outlook 2007 addin using EntryID.

Now I spend all the contacts in the contact folder:

string entryid = ...

Outlook.Application outlookApp = new Outlook.Application();
Outlook.MAPIFolder fldContacts = outlookApp.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts) as Outlook.MAPIFolder;
foreach (Outlook._ContactItem contact in fldContacts.Items)
{
    if (contact.EntryID==entryid) {
         contact.Display(false);
         break;
    }
}

but this is not an effective code for many contacts in the contacts folder

+5
source share
3 answers

You want to use the GetItemFromID method of the NameSpace object (not intuitively, it can be accessed through the Application.Session property, as you are doing above.)

You will need the store identifier of the MAPI store from which you want to receive the item. This can be easily extracted from the Folder object, to which you also already got a link.

string entryid = ...

var outlookApp = new Outlook.Application();
var outlookNS = outlookApp.Session;
var fldContacts = outlookNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts);
var contact = outlookNS.GetItemFromID(entryid, fldContacts.StoreID);
+3

:

var outlookNS = this.Application.Session;
var fldContacts = outlookNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts);
ContactItem contact = (ContactItem)outlookNS.GetItemFromID(entryid, fldContacts.StoreID);
contact.Display(false);
+2

I would recommend using the Folder.GetTable method to enumerate a large number of elements:

http://msdn.microsoft.com/en-us/library/bb147574(office.12).aspx

+1
source

All Articles