There doesn't seem to much information or any good code samples for setting an Outlook 2007 MailItem's categories programmatically.
MSDN has a limited page, and mentions using VB's Split function, saying more or less "you're on your own from here onwards, so sort it out yourself".
So far as I can tell we manipulate the Categories as a comma delimited string property of the mailitem. It seems a bit primitive, is that all there is to it?
Does everyone just dig out their library of string functions and parse the Categories property, trusting not to get in a muddle when multiple categories are set for a single mailitem and (heaven forbid) categories are renamed?
Best Answer
You can choose to manipulate the comma-delimited string of Categories any way you choose. To insert a category, I usually check if the current string is null and then just assign it. If the category is not null then I append it if it doesn't already exist. To remove an item, I just replace the category name with an empty string.
Adding Category
Removing Category
There are multitudes of ways to manipulate strings - they just chose to keep the serialized data structure simple underneath.
I tend to create my own Categories during Add-in startup to verify they exist. Certainly - category renaming is a concern, but if you are ensuring that your categories exist each time your add-in loads, you can at least ensure some level of validity.
To manage Outlook Categories, you can use ThisAddIn.Application.Session.Categories.