Load a Calendar in C# and VB.NET

Gembox.Email allows you to load a Calendar from a file or a stream in iCalendar format (.ics). The loaded Calendar can be modified, saved or added to a MailMessage object.

The following example shows how you can load a Calendar from an iCalendar file and display its properties and components. The calendar's components are Calendar.Tasks used for specifying to-do lists, and Calendar.Events used for specifying meeting requests, appointments, alarms, etc.

Load calendar in C# and VB.NET
Screenshot of Calendar's scheduling information
Upload your file (Drag file here)
using System;
using GemBox.Email;
using GemBox.Email.Calendar;

class Program
{
    static void Main()
    {
        // If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY");

        // Load calendar.
        Calendar calendar = Calendar.Load("Simple.ics");

        Console.WriteLine("CALENDAR");
        Console.WriteLine($"Method: {calendar.Method}");
        Console.WriteLine($"Events count: {calendar.Events.Count}");
        Console.WriteLine($"Tasks count: {calendar.Tasks.Count}");

        // Iterate through all events.
        Console.WriteLine();
        foreach (Event ev in calendar.Events)
        {
            Console.WriteLine("- EVENT");
            Console.WriteLine($"Organizer: {ev.Organizer}");
            Console.WriteLine($"Name: {ev.Name}");
            Console.WriteLine($"Start: {ev.Start:G}");
            Console.WriteLine($"End: {ev.End:G}");
            Console.WriteLine($"Reminders count: {ev.Reminders.Count}");

            // Iterate through all reminders.
            foreach (Reminder reminder in ev.Reminders)
            {
                Console.WriteLine("-- REMINDER");
                Console.WriteLine($"Action: {reminder.ReminderAction}");
                Console.WriteLine($"Days to trigger before start: {reminder.TriggerBeforeStart?.Days}");
            }
        }

        // Iterate through all tasks.
        Console.WriteLine();
        foreach (Task task in calendar.Tasks)
        {
            Console.WriteLine("- TASK");
            Console.WriteLine($"Organizer: {task.Organizer}");
            Console.WriteLine($"Name: {task.Name}");
            Console.WriteLine($"Start: {task.Start:G}");
            Console.WriteLine($"Deadline: {task.Deadline:G}");
            Console.WriteLine($"Reminders count: {task.Reminders.Count}");

            // Iterate through all reminders.
            foreach (Reminder reminder in task.Reminders)
            {
                Console.WriteLine("-- REMINDER");
                Console.WriteLine($"Action: {reminder.ReminderAction}");
                Console.WriteLine($"Days to trigger before start: {reminder.TriggerBeforeStart?.Days}");
            }
        }
    }
}
Imports System
Imports GemBox.Email
Imports GemBox.Email.Calendar

Module Program

    Sub Main()

        ' If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY")

        ' Load calendar.
        Dim calendar As Calendar = Calendar.Load("Simple.ics")

        Console.WriteLine("CALENDAR")
        Console.WriteLine($"Method: {calendar.Method}")
        Console.WriteLine($"Events count: {calendar.Events.Count}")
        Console.WriteLine($"Tasks count: {calendar.Tasks.Count}")

        ' Iterate through all events.
        Console.WriteLine()
        For Each ev As [Event] In calendar.Events

            Console.WriteLine("- EVENT")
            Console.WriteLine($"Organizer: {ev.Organizer}")
            Console.WriteLine($"Name: {ev.Name}")
            Console.WriteLine($"Start: {ev.Start:G}")
            Console.WriteLine($"End: {ev.End:G}")
            Console.WriteLine($"Reminders count: {ev.Reminders.Count}")

            ' Iterate through all reminders.
            For Each reminder As Reminder In ev.Reminders

                Console.WriteLine("-- REMINDER")
                Console.WriteLine($"Action: {reminder.ReminderAction}")
                Console.WriteLine($"Days to trigger before start: {reminder.TriggerBeforeStart?.Days}")
            Next
        Next

        ' Iterate through all tasks.
        Console.WriteLine()
        For Each task As Task In calendar.Tasks

            Console.WriteLine("- TASK")
            Console.WriteLine($"Organizer: {task.Organizer}")
            Console.WriteLine($"Name: {task.Name}")
            Console.WriteLine($"Start: {task.Start:G}")
            Console.WriteLine($"Deadline: {task.Deadline:G}")
            Console.WriteLine($"Reminders count: {task.Reminders.Count}")

            ' Iterate through all reminders.
            For Each reminder As Reminder In task.Reminders

                Console.WriteLine("-- REMINDER")
                Console.WriteLine($"Action: {reminder.ReminderAction}")
                Console.WriteLine($"Days to trigger before start: {reminder.TriggerBeforeStart?.Days}")
            Next
        Next
    End Sub
End Module

Want more?

Next example GitHub

Check the next example or select an example from the menu. You can also download our examples from the GitHub.


Like it?

Download Buy

If you want to try the GemBox.Email yourself, you can download the free version. It delivers the same performance and set of features as the professional version, but with some operations limited. To remove the limitation, you need to purchase a license.