开发者

How to colorize Categories for an Outlook AppointmentItem

I'm using the office .NET framework to create appointments in Outlook. The code that creates the appointments looks like this:

    private void createCalendarEvent(DateTime start, DateTime end, String dept, String subj, String subjType, String room)
    {
        AppointmentIte开发者_如何学Pythonm 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 just fine, but the category I'm setting does not have a colour associated with it. I want the appointments in outlook to appear in a different color depending on the category set. Is there some way i can manually set the category colours? Or even better, a way to get the framework to pick category colours for me automatically?


The answer to this question deals with categories. Specifically, here's some code (VB.net, but easily convertable) 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

Category colors are either set in Outlook, or in the code above when creating a category in code.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜