VCalendar Class

An iCalendar object ([RFC 5545], .ics): its events, to-dos, time zones and the other components.

public sealed class VCalendar : CalendarComponent

Example

var calendar = VCalendar.Load(path).Single();
var meeting = calendar.Events.First();
Assert.Equal("Weekly meeting", meeting.Summary);
Assert.Equal("Room 1; building A", meeting.Location);

// The start is 9:00 in Paris: the time zone of the calendar converts it to UTC
Assert.Equal(new DateTime(2026, 1, 5, 8, 0, 0, DateTimeKind.Utc), meeting.Start!.Value.ToUtc(calendar));
Assert.Equal(new DateTime(2026, 1, 5, 9, 0, 0), meeting.GetOccurrences().First());

var created = new VCalendar();
var ev = created.Add(new VEvent
{
    Uid = "launch@example.com",
    Summary = "Launch",
    Start = CalendarDateTime.FromUtc(new DateTime(2026, 6, 1, 14, 0, 0, DateTimeKind.Utc)),
    Duration = TimeSpan.FromHours(1),
    RecurrenceRule = RecurrenceRule.Parse("FREQ=WEEKLY;COUNT=4"),
});
var text = created.ToString();
Inheritance
CalendarComponent VCalendar

Constructors

NameDescription
VCalendar()Creates a calendar with the properties VERSION:2.0 and PRODID.

VCalendar()

VCalendar.cs

Creates a calendar with the properties VERSION:2.0 and PRODID.

public VCalendar()

Properties

NameDescription
EventsGets the events.
MethodGets or sets the method of an iTIP message (METHOD), such as REQUEST.
ProductIdGets or sets the identifier of the product that wrote the calendar (PRODID).
TimeZonesGets the time zones.
TodosGets the to-dos.

Gets the events.

public IEnumerable<VEvent> Events { get; }

Property value

IEnumerable<VEvent>

Gets or sets the method of an iTIP message (METHOD), such as REQUEST.

public string? Method { get; set; }

Property value

string?

ProductId

VCalendar.cs

Gets or sets the identifier of the product that wrote the calendar (PRODID).

public string? ProductId { get; set; }

Property value

string?

TimeZones

VCalendar.cs

Gets the time zones.

public IEnumerable<VTimeZone> TimeZones { get; }

Gets the to-dos.

public IEnumerable<VTodo> Todos { get; }

Property value

IEnumerable<VTodo>

Methods

NameDescription
Add<T>(T)Adds a component, such as an event.
AddAppointment(MapiAppointment)Adds an appointment of Outlook: an event, with its recurrence rule, the dates of its deleted occurrences (EXDATE), and an event per modified occurrence (RECURRENCE-ID). The times are in UTC.
AddMeetingMessage(MapiMeetingMessage)Adds a meeting message of Outlook, and sets the method of the calendar, so that it is an invitation of iTIP (RFC 5546): an invitation is METHOD:REQUEST, a cancellation METHOD:CANCEL with the status CANCELLED, and a response METHOD:REPLY, whose attendee is the sender with the participation status of the response, and whose organizer is the recipient.
AddTask(MapiTask)Adds a task of Outlook as a to-do.
FindTimeZone(string)Returns the definition of a time zone.
Load(Stream)Reads the calendars of a stream, until its end.
Load(ReadOnlySpan<byte>)Reads the calendars of a file, in UTF-8 (or Latin-1 when the bytes are not UTF-8).
Load(string)Reads the calendars of an .ics file.
Parse(string)Reads the calendars of a text (a file usually has one).
Save(string)Writes the calendar in an .ics file, in UTF-8.
ToMapiMeetingMessageBuilder()Converts the calendar, an invitation of iTIP (RFC 5546), to a meeting message of Outlook: METHOD:REQUEST to an invitation, METHOD:CANCEL to a cancellation, and METHOD:REPLY to the response its attendee gives (PARTSTAT).

Add<T>(T)

VCalendar.cs

Adds a component, such as an event.

public T Add<T>(T component) where T : CalendarComponent

Type parameters

T
The type of the component.

Parameters

component T
The component.

Returns

T The component.

AddAppointment(MapiAppointment)

VCalendar.cs

Adds an appointment of Outlook: an event, with its recurrence rule, the dates of its deleted occurrences (EXDATE), and an event per modified occurrence (RECURRENCE-ID). The times are in UTC.

public VEvent AddAppointment(MapiAppointment appointment)

Parameters

appointment MapiAppointment
The appointment.

Returns

VEvent The event of the appointment.

AddMeetingMessage(MapiMeetingMessage)

VCalendar.cs

Adds a meeting message of Outlook, and sets the method of the calendar, so that it is an invitation of iTIP (RFC 5546): an invitation is METHOD:REQUEST, a cancellation METHOD:CANCEL with the status CANCELLED, and a response METHOD:REPLY, whose attendee is the sender with the participation status of the response, and whose organizer is the recipient.

public VEvent AddMeetingMessage(MapiMeetingMessage message)

Parameters

message MapiMeetingMessage
The meeting message.

Returns

VEvent The event of the meeting.

Example

var invitation = VCalendar.Parse("""
    BEGIN:VCALENDAR
    VERSION:2.0
    PRODID:-//Example//Example//EN
    METHOD:REQUEST
    BEGIN:VEVENT
    UID:meeting-42@example.com
    SEQUENCE:1
    DTSTAMP:20260301T080000Z
    DTSTART:20260302T090000Z
    DTEND:20260302T100000Z
    SUMMARY:Project review
    LOCATION:Room 1
    ORGANIZER;CN=Alice:mailto:alice@example.com
    ATTENDEE;CN=Bob;ROLE=REQ-PARTICIPANT:mailto:bob@example.com
    END:VEVENT
    END:VCALENDAR
    """)[0];

// The invitation as a meeting request of Outlook
var request = Assert.IsType<MapiMeetingMessage>(MsgFile.Load(MsgFile.ToByteArray(invitation.ToMapiMeetingMessageBuilder())));
Assert.Equal(MapiMeetingMessageType.Request, request.MeetingMessageType);
Assert.Equal("IPM.Schedule.Meeting.Request", request.MessageClass);
Assert.Equal("meeting-42@example.com", request.Uid);
Assert.Equal("alice@example.com", request.SenderEmailAddress);
Assert.Equal("bob@example.com", request.Recipients.Single().EmailAddress);

// And back as an invitation
var calendar = new VCalendar();
var meeting = calendar.AddMeetingMessage(request);
Assert.Equal("REQUEST", calendar.Method);
Assert.Equal("meeting-42@example.com", meeting.Uid);
Assert.Equal(1, meeting.Sequence);

AddTask(MapiTask)

VCalendar.cs

Adds a task of Outlook as a to-do.

public VTodo AddTask(MapiTask task)

Parameters

task MapiTask
The task.

Returns

VTodo The to-do.

FindTimeZone(string)

VCalendar.cs

Returns the definition of a time zone.

public VTimeZone? FindTimeZone(string id)

Parameters

id string
The identifier of the time zone (TZID).

Returns

VTimeZone? The time zone, or null when the calendar does not define it.

Load overloads

Load(Stream)

VCalendar.cs

Reads the calendars of a stream, until its end.

public static IReadOnlyList<VCalendar> Load(Stream stream)
Parameters
stream Stream
The stream.
Returns

IReadOnlyList<VCalendar> The calendars.

Exceptions
InvalidEmailDataException
The components are nested deeper than 32 levels.
EmailResourceLimitException
The content is larger than 64 MB.

Load(ReadOnlySpan<byte>)

VCalendar.cs

Reads the calendars of a file, in UTF-8 (or Latin-1 when the bytes are not UTF-8).

public static IReadOnlyList<VCalendar> Load(ReadOnlySpan<byte> data)
Parameters
data ReadOnlySpan<byte>
The content of the file.
Returns

IReadOnlyList<VCalendar> The calendars.

Exceptions
InvalidEmailDataException
The components are nested deeper than 32 levels.

Load(string)

VCalendar.cs

Reads the calendars of an .ics file.

public static IReadOnlyList<VCalendar> Load(string path)
Parameters
path string
The path of the file.
Returns

IReadOnlyList<VCalendar> The calendars.

Exceptions
InvalidEmailDataException
The components are nested deeper than 32 levels.
EmailResourceLimitException
The content is larger than 64 MB.

Parse(string)

VCalendar.cs

Reads the calendars of a text (a file usually has one).

public static IReadOnlyList<VCalendar> Parse(string text)

Parameters

text string
The text.

Returns

IReadOnlyList<VCalendar> The calendars.

Exceptions

InvalidEmailDataException
The components are nested deeper than 32 levels.

Save(string)

VCalendar.cs

Writes the calendar in an .ics file, in UTF-8.

public void Save(string path)

Parameters

path string
The path of the file.

ToMapiMeetingMessageBuilder()

VCalendar.cs

Converts the calendar, an invitation of iTIP (RFC 5546), to a meeting message of Outlook: METHOD:REQUEST to an invitation, METHOD:CANCEL to a cancellation, and METHOD:REPLY to the response its attendee gives (PARTSTAT).

public MapiMeetingMessageBuilder ToMapiMeetingMessageBuilder()

Returns

MapiMeetingMessageBuilder The builder of the meeting message, from the first event of the calendar.

Exceptions

InvalidOperationException
The calendar has no event, or its method is not the one of a meeting message.