InfiniTec - Henning Krauses Blog

Don't adjust your mind - it's reality that is malfunctioning

Working with the Master Category List–EWS edition

Back in 2008 I wrote an article about accessing the Master Category List using WebDAV. If you are not sure what the Master Category List is, read that article first…

EWS could not be used at that time, since access to the Folder Associated Items via EWS is a Feature of Exchange 2010. So if you are on Exchange 2007, the old article still applies.

The last article contained some code which simplified updating the list. I’ve updated the code and aligned the method naming with that of the EWS managed API.

This is the class diagram for the updated code:

ClassDiagram

The classes are really easy to use:

var service = new ExchangeService(ExchangeVersion.Exchange2010_SP1) { Credentials = new NetworkCredential("someone@infinitec.de", "password") };
service.AutodiscoverUrl("someone@infinitec.de", url => true);

var list = MasterCategoryList.Bind(service);
foreach (var category in list.Categories)
{
    Console.Out.WriteLine("category = {0}", category.Name);
}

The only interesting line in the sample above is line 4. The call to MasterCategoryList.Bind() loads the MasterCategoryList from the users Exchange Mailbox. After that, the name of each console is written to the console.

Adding a new category is equally simple:

var service = new ExchangeService(ExchangeVersion.Exchange2010_SP1) { Credentials = new NetworkCredential("someone@infinitec.de", "password") };
service.AutodiscoverUrl("someone@infinitec.de", url => true);

var list = MasterCategoryList.Bind(service);
list.Categories.Add(new Category("Vacation", CategoryColor.DarkMaroon, CategoryKeyboardShortcut.CtrlF10));
list.Update();

This will add a new category named “Vacation” to the list.

So how does this work? The Master Category List is stored in a hidden message in the calendar folder of a mailbox. EWS in 2010 provides simple access to this message with the UserConfiguration class. This code show how the Master Category List is loaded:

var item = UserConfiguration.Bind(service, "CategoryList", WellKnownFolderName.Calendar,
                                  UserConfigurationProperties.XmlData);

var reader = new StreamReader(new MemoryStream(item.XmlData), Encoding.UTF8, true);

The configuration data is stored in the XmlData property as UTF-8 encoded byte array.

Here is the new code:


Posted by Henning Krause on Thursday, July 28, 2011 4:00 PM, last modified on Wednesday, July 27, 2011 12:22 PM
Permalink | Post RSSRSS comment feed

Comments (1) -

On 3/16/2012 4:36:44 PM BR wrote:

BR

Hi Henning,
First thanks for the very useful code. Exchange/Outlook Categories are kindof confusing subject.
Your code is accessing hidden master category list, but I couldn't find the PowerShell command to do the same thing. At the same time PS command Get-MessageCategory retrieves categories for the Mailbox, which appears to be separate list.
In Outlook I can create and use categories anywhere: Mailboxes, Contacts, Tasks, Public Folders, but PS command Get-MessageCategory works only for Mailboxes.
I did some testing and it seems that all user account objects (like Mailboxes, Contacts, Tasks, etc.) use Mailbox defined message categories, while global objects like Public folders use and can alter Master Category List. I created a post in Public Folder and assigned a newly created category to it. Guess what: this new, Outlook created, category showed up in the  Master Category List.
Do you have any documentation resources explaining in detail how Exchange category lists are structured?
Best Regards,
Boris

Reply

Add comment

biuquote
  • Comment
  • Preview
Loading