This project has moved and is read-only. For the latest updates, please go here.

add a categorie using netoffice in c#

Jan 20, 2013 at 4:04 PM
Edited Jan 20, 2013 at 4:10 PM

Hi. I am having trouble adding a custom category to Outlook.
I simply use:

Outlook.Application _outlookApplication;
string customCat = "MyCat";
if (!CategoryExists(customCat)) {
 	Outlook._Categories categories = _outlookApplication.Session.Categories;
	categories.Add(customCat, Color.Orange);

CategoryExists works. I have checked this. It fails at categories.Add(customCat, Color.Orange). It throws an inner exception with message: Exception has been thrown by the target of an invocation. If I do a


it returns 9, which are the number of categories I have in Outlook.

This is driving me nuts. Any help would be greatly appreciated.

Jan 20, 2013 at 5:20 PM

You should use Outlook color constant instead of System.Drawing.Color property:

categories.Add(customCat, Outlook.Enums.OlCategoryColor.olCategoryColorOrange);
Jan 20, 2013 at 8:16 PM

Oh man. How could I have missed that!


Thanks artnib!