Class CalendarReader
Contents
[
Hide
]CalendarReader class
Reads the events of an iCalendar (ICS) file or stream one by one.
public class CalendarReader
Constructors
| Name | Description |
|---|---|
| CalendarReader(Stream) | Initializes a new instance of the CalendarReader class that reads the specified stream with the default options. |
| CalendarReader(string) | Initializes a new instance of the CalendarReader class that reads the specified file with the default options. |
| CalendarReader(Stream, AppointmentLoadOptions) | Initializes a new instance of the CalendarReader class that reads the specified stream with the specified options. |
| CalendarReader(string, AppointmentLoadOptions) | Initializes a new instance of the CalendarReader class that reads the specified file with the specified options. |
Properties
| Name | Description |
|---|---|
| Count { get; } | Gets the number of events (VEVENT components) in the calendar. |
| Current { get; } | Gets the event read by the last call to NextEvent, or null before the first call. |
| IsMultiEvents { get; } | Gets a value indicating whether the calendar contains more than one event. |
| Method { get; } | Gets the iCalendar METHOD of the calendar. |
| Version { get; } | Gets the version of the calendar: 2.0 for iCalendar, 1.0 for vCalendar. |
Methods
| Name | Description |
|---|---|
| LoadAsMultiple() | Reads all events of the calendar. |
| NextEvent() | Reads the next event and makes it available in Current. |
Remarks
Use this class for calendars that hold more than one event, where Load would return only a single appointment.
The calendar is parsed when the reader is created. Call NextEvent until it returns false and take each event from Current, or call LoadAsMultiple to get all events at once. Only events (VEVENT components) are read; tasks and free/busy components are ignored.
The reader holds no open handle on the source: a file is read and closed inside the constructor, so there is nothing to dispose of afterwards.
Examples
This example demonstrates how to read multiple events from an ICS file and store them in a list of Appointment objects.
[C#]
// Create a list to hold the appointments
var appointments = new List<Appointment>();
// Initialize CalendarReader with the ICS file path
var reader = new CalendarReader("US-Holidays.ics");
// Iterate through the events in the ICS file
while (reader.NextEvent())
{
// Add the current event to the appointments list
appointments.Add(reader.Current);
}
// Working with the appointments...
[Visual Basic]
' Create a list to hold the appointments
Dim appointments As New List(Of Appointment)
' Initialize CalendarReader with the ICS file path
Dim reader As New CalendarReader("US-Holidays.ics")
' Iterate through the events in the ICS file
While reader.NextEvent()
' Add the current event to the appointments list
appointments.Add(reader.Current)
End While
' Working with the appointments...
See Also
- namespace Aspose.Email.Calendar
- assembly Aspose.Email