none
Creating category colours with EWS - colour not showing in OWA RRS feed

  • Question

  • I am using EWS to create appointments in staff calendars. Each appointment is given at least one category. Once the appointments have been made the categories and their colours are added to the master category list. If I view the result on desktop Outlook the results are as expected. However, on Web Outlook (or whatever it is currently called) the category appears without a colour. If I go to edit the appointment and click the category list the new, color-coded category is there on the list but the category on the appointment has not taken up the colour.

    Any thoughts on why this happens and how I can work around it?


    Mike VE

    • Moved by Chenchen Li Thursday, March 16, 2017 7:44 AM
    Wednesday, March 15, 2017 10:32 AM

Answers

  • Hi,

    This is how to retrieve the categories assign to an appointment through Extended Properties:

    //int : Category Color Code
    ExtendedPropertyDefinition EpCategoryColorCode = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.Appointment, 33300, MapiPropertyType.Integer);
    //string: Category Name
    ExtendedPropertyDefinition epCategoryName = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.PublicStrings, "Keywords", MapiPropertyType.StringArray);
    
    

    And How to assign categories to an appointment:

    //Load Categories property of appointment
    appointment.Load(new PropertySet(AppointmentSchema.Categories));
    //set Categories property,
    string[] categoryName = new string[1] { "Red Category" };
    appointment.Categories = new StringList(categoryName);
     appointment.Update(ConflictResolutionMode.AlwaysOverwrite, SendInvitationsOrCancellationsMode.SendToNone);
    The categorie to be added to the appointment must already exist in the mailbox. I give you below the code needed to add it.
     public static void AddCategory(CalendarFolder calendarFolder, Category category)
        {
            SearchFilter _itemClassFilter = new SearchFilter.IsEqualTo(EmailMessageSchema.ItemClass, "IPM.Configuration.CategoryList");
            ExtendedPropertyDefinition categories = new ExtendedPropertyDefinition(0x7C08, MapiPropertyType.Binary);
            ItemView view = new ItemView(1);
            view.Traversal = ItemTraversal.Associated;
            
            FindItemsResults<Item> items = calendarFolder.FindItems(_itemClassFilter, view);
            if (items.TotalCount > 0)
            {
                try
                {
                    EmailMessage msg = items.First() as EmailMessage;
                  
                    msg.Load(new PropertySet(ItemSchema.Id, categories));
                    Guid guid = Guid.NewGuid();
                    string newCategory = Properties.Settings.Default.Category.Replace("%NAME%", category.Name).Replace("%COLOR%", category.Color.ToString()).Replace("%GUID%", "{" + guid.ToString() + "}");
                    
                    string xmlString = Encoding.UTF8.GetString((byte[])msg.ExtendedProperties[0].Value);
                 
                    xmlString = xmlString.Replace("</categories>", newCategory);
                    byte[] value = Encoding.UTF8.GetBytes(xmlString);
                    msg.SetExtendedProperty(categories, value);
                    msg.Update(ConflictResolutionMode.AlwaysOverwrite);
                }
                catch (Exception)
                {
                    throw;
                }
            }
        }


    • Marked as answer by Mike VE Wednesday, March 22, 2017 12:55 PM
    Wednesday, March 22, 2017 10:42 AM
  • Thanks for the reply. I have just got it solved this morning. There were a number of things going on which compounded things. In some cases the category added to the appointment was not the exactly the same as the category added to the user's Master Category List - a difference of case. Outlook desktop seemed to cope with this but OWA did not.

    I was adding categories to the master list without a GUID, now fixed.

    Lastly, as you pointed out, the categories must be added to the Master Category List before the appointments with the matching categories are created.


    Mike VE

    • Marked as answer by Mike VE Wednesday, March 22, 2017 12:55 PM
    Wednesday, March 22, 2017 12:55 PM

All replies

  • Hello Mike,

    This forum is used for discussing issues when developing VSTO add-ins with Office Object Model. 

    According to your description, I think you are using EWS Managed API, so I would move this thread into Exchange Server Development.

    Sorry for any inconvenience and thanks for your understanding.

    Regards,

    Celeste


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, March 16, 2017 7:43 AM
  • Hi,

    This is how to retrieve the categories assign to an appointment through Extended Properties:

    //int : Category Color Code
    ExtendedPropertyDefinition EpCategoryColorCode = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.Appointment, 33300, MapiPropertyType.Integer);
    //string: Category Name
    ExtendedPropertyDefinition epCategoryName = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.PublicStrings, "Keywords", MapiPropertyType.StringArray);
    
    

    And How to assign categories to an appointment:

    //Load Categories property of appointment
    appointment.Load(new PropertySet(AppointmentSchema.Categories));
    //set Categories property,
    string[] categoryName = new string[1] { "Red Category" };
    appointment.Categories = new StringList(categoryName);
     appointment.Update(ConflictResolutionMode.AlwaysOverwrite, SendInvitationsOrCancellationsMode.SendToNone);
    The categorie to be added to the appointment must already exist in the mailbox. I give you below the code needed to add it.
     public static void AddCategory(CalendarFolder calendarFolder, Category category)
        {
            SearchFilter _itemClassFilter = new SearchFilter.IsEqualTo(EmailMessageSchema.ItemClass, "IPM.Configuration.CategoryList");
            ExtendedPropertyDefinition categories = new ExtendedPropertyDefinition(0x7C08, MapiPropertyType.Binary);
            ItemView view = new ItemView(1);
            view.Traversal = ItemTraversal.Associated;
            
            FindItemsResults<Item> items = calendarFolder.FindItems(_itemClassFilter, view);
            if (items.TotalCount > 0)
            {
                try
                {
                    EmailMessage msg = items.First() as EmailMessage;
                  
                    msg.Load(new PropertySet(ItemSchema.Id, categories));
                    Guid guid = Guid.NewGuid();
                    string newCategory = Properties.Settings.Default.Category.Replace("%NAME%", category.Name).Replace("%COLOR%", category.Color.ToString()).Replace("%GUID%", "{" + guid.ToString() + "}");
                    
                    string xmlString = Encoding.UTF8.GetString((byte[])msg.ExtendedProperties[0].Value);
                 
                    xmlString = xmlString.Replace("</categories>", newCategory);
                    byte[] value = Encoding.UTF8.GetBytes(xmlString);
                    msg.SetExtendedProperty(categories, value);
                    msg.Update(ConflictResolutionMode.AlwaysOverwrite);
                }
                catch (Exception)
                {
                    throw;
                }
            }
        }


    • Marked as answer by Mike VE Wednesday, March 22, 2017 12:55 PM
    Wednesday, March 22, 2017 10:42 AM
  • Thanks for the reply. I have just got it solved this morning. There were a number of things going on which compounded things. In some cases the category added to the appointment was not the exactly the same as the category added to the user's Master Category List - a difference of case. Outlook desktop seemed to cope with this but OWA did not.

    I was adding categories to the master list without a GUID, now fixed.

    Lastly, as you pointed out, the categories must be added to the Master Category List before the appointments with the matching categories are created.


    Mike VE

    • Marked as answer by Mike VE Wednesday, March 22, 2017 12:55 PM
    Wednesday, March 22, 2017 12:55 PM