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:

Sourcecode Download


Posted by Henning Krause on Thursday, July 28, 2011 4:00 PM, last modified on Tuesday, June 11, 2013 4:52 PM
Permalink | Post RSSRSS comment feed

Comments (4) -

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

On 11/1/2013 2:01:02 PM Simon wrote:

Simon

Hej Henning

I'm trying to get the Master Categorylist of a user, but gets the exception:

Microsoft.Exchange.WebServices.Data.ServiceResponseException: The specified object was not found in the store.
   at Microsoft.Exchange.WebServices.Data.ServiceResponse.InternalThrowIfNecessary()
   at Microsoft.Exchange.WebServices.Data.ServiceResponse.ThrowIfNecessary()
   at Microsoft.Exchange.WebServices.Data.MultiResponseServiceRequest`1.Execute()
   at Microsoft.Exchange.WebServices.Data.ExchangeService.GetUserConfiguration(String name, FolderId parentFolderId, UserConfigurationProperties properties)
   at Microsoft.Exchange.WebServices.Data.UserConfiguration.Bind(ExchangeService service, String name, FolderId parentFolderId, UserConfigurationProperties properties)
   at Microsoft.Exchange.WebServices.Data.UserConfiguration.Bind(ExchangeService service, String name, WellKnownFolderName parentFolderName, UserConfigurationProperties properties)
   at UTRGetInfo.MasterCategoryList.MasterCategoryList.Bind(ExchangeService service)

I need to instanciate the MasterCategoryList, so i can add new categories programatically to a users master category list.
I've tested many thing and found out this exception will be the response if the users dosnt have any appointments in the calendar.

Any idea how can i get arround this issue and still update the user Master Category List on the Exchange server?

On 11/1/2013 2:02:53 PM Simon wrote:

Simon

In previous post.

'I'm' = I am

On 11/1/2013 2:54:31 PM Simon wrote:

Simon

Correction to my first post.

"I have testet many things and found out, this exception is the response if the users dont have used categories in any of the appointments in the calendars"

Thx Simon