Search code examples
c#outlooksharedmapi

Outlook Mapi access shared contacts


I want to import contacts from Outllok via Mapi. First step with standard contact is no problem:

MAPIFolder contactObjects = 
outlookObj.Session.GetDefaultFolder(OlDefaultFolders.olFolderContacts);
foreach (ContactItem contactObject in contactObjects.Items) {
    ... import contact ...
}

In a second step I additionally want to import shared contacts. Only thing I found was using

OpenSharedItem(sharedContacts.vcf)

but I don't know the name of the file (shared item) I want to open. Does someone know how to access shared contacts and can help me out?

Tobi


Update:

Thanks for the hint with the vcf-Files. But where do I find them?


Update2:

I played around with OutlookSpy. I got access to the folder with shared contacts, but only by knowing the id (which is of course different for other users):

var ns = outlookObj.GetNamespace("MAPI");
var flr = ns.GetFolderFromID("00000000176A90DED92CE6439C1CB89AFE3668F90100D1AD8F66B576B54FB731302D9BB9F6C40007E4BAC5020000");

foreach (var contactObject in flr.Items) {
       ...
}

How do I get access to the folder without knowing the id?


Solution

  • Well the solution to the question as it is asked in the title is almost simple. You just need to call:

    Recipient recip = Application.Session.CreateRecipient("Firstname Lastname");
    MAPIFolder sharedContactFolder = Application.Session.GetSharedDefaultFolder(recip, OlDefaultFolders.olFolderContacts);
    

    Because this does not solve my problem I will ask another question!