简体   繁体   中英

How can I read in the cache entries from outlook and then save them as contacts in my address book?

I am currently programming an Outlook Add-in with C# in Visual Studio. Now I would like to read in existing entries of the cache in order to automatically save the contacts contained therein as an entry in my address book. Can anyone help me further on how I can access the cache and then implement my function?

So far I already did following steps:

public partial class ThisAddIn
{
...
private Outlook.Application OutlookApplication;
private MAPIFolder inboxFolder;
...
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
...
 inboxFolder = Application.GetNamespace("MAPI").GetDefaultFolder(OlDefaultFolders.olFolderInbox);
...
}

private void saveContact()
{
StorageItem storage = inboxFolder.GetStorage("IPM.Configuration.Autocomplete", OlStorageIdentifierType.olIdentifyByEntryID);
PropertyAccessor propertyAcc = storage.PropertyAccessor;
byte[] got = propertyAcc.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x7C090102");
}

I am currently calling the method for testing when opening an inspector.

So far I get the following error message: System.Runtime.InteropServices.COMException: "The StorageItem item cannot be created in this folder. Either the folder is read-only, or storage items are not allowed in this folder. "

Can somebody help me fix my error?

The autocomplete (nickname) cache stream is stored in a hidden message with the message class of IPM.Configuration.Autocomplete in the Inbox folder (see the associated content of the folder). The format is documented, see Nickname cache . You can access that message using MAPIFolder.GetStorage and then you can get the stream itself:

Set propAcc = storage.PropertyAccessor
Set got = propertyAcc.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x7C090102")

You may find the Get autocomplete address list of Outlook in VBA thread helpful.

Autocomplete stream is stored as a hidden (associated) message with the message class of "IPM.Configuration.Autocomplete" in the Inbox folder. You can see the data in OutlookSpy (I am its author): go to the Inbox folder, click IMAPIFolder button on the OutlookSpy ribbon, go to the "Associated Contents" tab, locate a message with PR_MESSAGE_CLASS == "IPM.Configuration.Autocomplete", select the PR_ROAMING_BINARYSTREAM property to see its contents.

You can open that message using the Outlook Object Model ( MAPIFolder.GetStorage("IPM.Configuration.Autocomplete", OlStorageIdentifierType.olIdentifyByMessageClass ), read the property using PropertyAccessor.GetProperty , then parse it. Note that large (>30kB) autocomplete streams cannot be opened using PropertyAccessor .

If using Redemption an option (I am also its author), it exposes autocomplete as the RDONicknames collection:

 set Session = CreateObject("Redemption.RDOSession")
 Session.MAPIOBJECT = Application.Session.MAPIOBJECT
 set Nicknames = Session.GetNicknames
 for each NickName in NickNames
     Debug.Print NickName.Name & " - " & NickName.SmtpAddress
 next

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM