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:

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: