views:

280

answers:

1

I want to write a simple Outlook 2007 AddIn that allows me to manually Auto-Archive mails. That is, I right-click a mail, select Auto-Archive and it gets moved into my Archive folder.

Unfortunately, I do not seem to be able to detect which one is the Archive Storage. I know that Application.GetNamespace("MAPI").Stores is a list of all my stores, and this includes my Archive Store. But I do not seem to find a way to detect if a store is the Archive Store or not.

Before you recommend simple string matching against store.DisplayName keep in mind localization (in German, the Store is "Archivordner", which is obviously different from the english one).

I was thinking that it could be possible to access the Auto Archive setting to get the Filename and then match against store.FilePath, but I am unable to find this setting anywhere.

Any suggestions?

+1  A: 

Okay, found it. The Secret is IPC.MS.Outlook.AgingProperties and it's a bit weird and undocumented, but it's good enough for me.

    private bool GetArchiveFilename(MAPIFolder fld, out string archiveFileName)
    {
        bool result = false;
        archiveFileName = string.Empty;
        if (fld != null)
        {
            StorageItem si = fld.GetStorage("IPC.MS.Outlook.AgingProperties", OlStorageIdentifierType.olIdentifyByMessageClass);

            try
            {
                archiveFileName = si.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x6859001E").ToString();
                result = true;
            }
            catch (COMException)
            {
                return GetArchiveFilename(fld.Parent as MAPIFolder, out archiveFileName);
            }
        }
        return result;
    }
Michael Stum