VCalendar Class
An iCalendar object ([RFC 5545], .ics): its events, to-dos, time zones and the other components.
public sealed class VCalendar : CalendarComponentExample
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
CalendarComponentVCalendar
Constructors
| Name | Description |
|---|---|
| VCalendar() | Creates a calendar with the properties VERSION:2.0 and PRODID. |
VCalendar()
VCalendar.csCreates a calendar with the properties VERSION:2.0 and PRODID.
public VCalendar()Properties
| Name | Description |
|---|---|
| Events | Gets the events. |
| Method | Gets or sets the method of an iTIP message (METHOD), such as REQUEST. |
| ProductId | Gets or sets the identifier of the product that wrote the calendar (PRODID). |
| TimeZones | Gets the time zones. |
| Todos | Gets the to-dos. |
Events
VCalendar.csMethod
VCalendar.csProductId
VCalendar.csTimeZones
VCalendar.csTodos
VCalendar.csMethods
| Name | Description |
|---|---|
| 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.csAdds a component, such as an event.
public T Add<T>(T component) where T : CalendarComponentType parameters
T- The type of the component.
Parameters
componentT- The component.
Returns
T The component.
AddAppointment(MapiAppointment)
VCalendar.csAdds 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)AddMeetingMessage(MapiMeetingMessage)
VCalendar.csAdds 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
messageMapiMeetingMessage- 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.csFindTimeZone(string)
VCalendar.csReturns the definition of a time zone.
Parameters
idstring- 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.csReads the calendars of a stream, until its end.
public static IReadOnlyList<VCalendar> Load(Stream stream)Parameters
streamStream- 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.csReads 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
dataReadOnlySpan<byte>- The content of the file.
Returns
IReadOnlyList<VCalendar> The calendars.
Exceptions
InvalidEmailDataException- The components are nested deeper than 32 levels.
Load(string)
VCalendar.csReads the calendars of an .ics file.
public static IReadOnlyList<VCalendar> Load(string path)Parameters
pathstring- 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.csReads the calendars of a text (a file usually has one).
public static IReadOnlyList<VCalendar> Parse(string text)Parameters
textstring- The text.
Returns
IReadOnlyList<VCalendar> The calendars.
Exceptions
InvalidEmailDataException- The components are nested deeper than 32 levels.
Save(string)
VCalendar.csToMapiMeetingMessageBuilder()
VCalendar.csConverts 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.