Categories not persisted between sessions in Outlook 2007

T

Teodora Gancheva

Hi,

I have a C# COM Add-in for Outlook 2007 that adds categories to mail
messages programmatically. I use mapiNameSpace.Categories.Add method to add
the category to the Master Category List and the Categories property of the
MailItem to assign the category to the mail. This works fine and the category
is successfully added to the mail and to the Master Category List.
However, when Outlook 2007 is restarted only the category assigned to the
mail is persisted. The category disappears from the Master Category List.
I am using Outlook 2007 SP2 with Exchange account. Has anyone encountered
this issue before? I found very little information on the net about Outlook
categories, so any hint is highly appreciated.
Thanks,
Teodora Gancheva
 
T

Teodora Gancheva

This is how I add the category to Outlook category list:

NameSpace mapiNameSpace = outlook.GetNamespace("MAPI");
mapiNameSpace.Categories.Add(categoryName,
OlCategoryColor.olCategoryColorNone,
OlCategoryShortcutKey.olCategoryShortcutKeyNone);

And then I assign the category to the MailItem:

mail.Categories = categoryName;
mail.Save();

Thanks,
Teodora Gancheva
 
K

Ken Slovak - [MVP - Outlook]

I'm seeing it as a bug, it's not persisting here either. Structure your code
so you add that custom category when your code starts up.

I'll report it to MS and see what they say.
 
T

Teodora Gancheva

Hi,

In the meantime I have tested the code on 5 different machines with Outlook
2007. It seems to be working on the RTM and SP1 versions. The issue only
exists with SP2.
Unfortunatelly, adding the categories upon start up is not applicable in my
scenario, or at the very least is very difficult. The reason is that I am
assigning different categories to different mail items upon user action, in
my case that is import of the email into an external system. I could probably
save the categories to some file and then upon start up read from that file
....
Anyways, let's see what MS have to say about this.

Thanks,
Teodora Gancheva
 
K

Ken Slovak - [MVP - Outlook]

The bug was verified by 2 other Outlook MVP's independently, so it's
definitely a bug. We all tested on Outlook 2007 SP2, so it's definitely
there.

It's been reported to MS, but I doubt anything will be fixed until SP3. It's
not a data corruption or loss problem that would require a hot fix, and the
product group is devoting most or all of their time at the moment to the
Outlook 2010 beta, so I don't see it getting high priority at this time.
BTW, the bug isn't there in the beta of Outlook 2010.

What I've done in addins where I use Categories is to have a list either in
Settings or in an XML file that I read at startup and then add my categories
to the collection as needed (if they're not there).

One of the other MVP's (who has an addin that manages categories) hacks any
custom categories into the binary property PR_ROAMING_XMLSTREAM (0x7C080102)
in the hidden item in the Calendar folder that is where the master category
list is stored. All the categories are stored there in that property in a
hidden item with the MessageClass of "IPM.Configuration.CategoryList".

Doing it that way will make the added categories permanent, since that's
where Outlook looks for the categories list. If you open that hidden item in
a MAPI viewer such as OutlookSpy (www.dimastr.com) or MFCMAPI you can look
at that binary property to see how each category entry is formatted. The
binary bits are actually XML text, so you can extract that and review how
each entry is structured. You could then get the bits as a binary array,
convert the array into a text string that's XML and use XML methods to read
and add nodes as needed. Then when finished you can simply convert the XML
text back into a binary array of bytes and write that back into the
PR_ROAMING_XMLSTREAM property on the hidden item.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top