Setting an Outlook mailitem's category programmatically?
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
var customCat = "Custom Category";
if (mailItem.Categories == null) // no current categories assigned
mailItem.Categories = customCat;
else if (!mailItem.Categories.Contains(customCat)) // insert as first assigned category
mailItem.Categories = string.Format("{0}, {1}", customCat, mailItem.Categories);
Removing Category
var customCat = "Custom Category";
if (mailItem.Categories.Contains(customCat))
mailItem.Categories = mailItem.Categories.Replace(string.Format("{0}, ", customCat), "").Replace(string.Format("{0}", customCat), "");
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.
var customCat = "Custom Category";
if (Application.Session.Categories[customCat] == null)
Application.Session.Categories.Add(customCat, Outlook.OlCategoryColor.olCategoryColorDarkRed);