How to colorize categories for Outlook AppointmentItem

I am using the Office.NET platform to create appointments in Outlook. The code that creates the meetings is as follows:

    private void createCalendarEvent(DateTime start, DateTime end, String dept, String subj, String subjType, String room)
    {
        AppointmentItem apt = (AppointmentItem)OLapp.CreateItem(OlItemType.olAppointmentItem);

        apt.Start = start;
        apt.End = end;
        apt.Subject = subj + " - " + subjType;
        apt.Body = "Subject: " + subj + " (" + subjType + ")"
                + "\nDepartment: " + dept
                + "\nRoom: " + room
                + "\n\nCreated by " + this.Text
                + "\n On " + DateTime.Now.ToLongDateString() + " At " + DateTime.Now.ToLongTimeString();
        apt.Location = room;
        apt.Categories = subj;
        apt.Save();
    }

This works fine, but the category I am setting does not have a color associated with it. I want meetings in Outlook to look different depending on the set of categories. Is there a way that I can manually set the colors of categories? Or is it even better to get a framework for automatically selecting category colors for me?

+3
source share
1 answer

The answer to this question is categories. In particular, here is some code (VB.net, but easily convertible) that will create a dark olive category:

Private Shared ReadOnly CATEGORY_TEST As String = "Custom Overdue Activity"

' This method checks if our custom category exists, and creates it if it doesn't.
Private Sub SetupCategories()
    Dim categoryList As Categories = Application.Session.Categories
    For i As Integer = 1 To categoryList.Count
        Dim c As Category = categoryList(i)
        If c.Name.Equals(CATEGORY_TEST) Then
            Return
        End If
    Next

    categoryList.Add(CATEGORY_TEST, Outlook.OlCategoryColor.olCategoryColorDarkOlive)
End Sub

Outlook, .

+1

Source: https://habr.com/ru/post/1789881/


All Articles