Eric's Blog

Day to day experience in .NET
Welcome to Blogs @ IRM Sign in | Join | Help
 Search

Disclaimer

The content of this site is my own personal opinion and does not in any way represent my employer, it's subsideries or affiliates. These postings are provided "AS IS" with no warranties, and confer no rights.

This Blog

The Small Things: How to Show the Color Categories in Outlook

In an add-in for Outlook that I’m developing I wanted to show the built in Color Categories dialog so that the user could choose categories in a familiar way. The categories should be set on an object that is unique for the add-in (aka not for a mail or calendar item). I couldn’t find any way to show the dialog itself and when searching Internet I found nothing useful, but I have found an acceptable workaround. On the AppointmentItem (or one of the others) there is a method called ShowCategoriesDialog which shows the dialog, so what I did was to create a temporary appointment item, setting my categories, showing the dialog, read the Categories property and then finally cleaning up. Here is the code:

private void ShowAllCategories()
{
    Microsoft.Office.Interop.Outlook.Items items = IRM.TimeManager.Outlook.Globals.ThisAddIn.Calendar.Items;
    Microsoft.Office.Interop.Outlook.AppointmentItem item = (Microsoft.Office.Interop.Outlook.AppointmentItem)items.Add();

    try
    {
        item.Categories = MyObject.Categories ?? string.Empty;
        item.ShowCategoriesDialog();
        MyObject.Categories = item.Categories;
    }
    finally
    {
        if (item != null)
        {
            item.Delete();
            System.Runtime.InteropServices.Marshal.FinalReleaseComObject(item);
        }
        if (items != null)
            System.Runtime.InteropServices.Marshal.FinalReleaseComObject(items);
    }
}
Published den 11 augusti 2010 17:26 by ericqu

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Leave a Comment

(required) 
(optional)
(required) 
Submit
Powered by Community Server, by Telligent Systems