Create and Save a Calendar in C# and VB.NET

Gembox.Email provides an advanced API for working with calendars, events, tasks, and reminders.

It is possible to create a new calendar, load it from a file in iCalendar (ics) format, or get it from a MailMessage. Afterwards, the calendar can be modified and saved to a file in iCalendar (ics) format or added to a MailMessage, which can be later sent or saved to a file.

The following example shows how to create a calendar with events, tasks, and reminders and save it to a file in iCalendar (ics) format.

Screenshot
Save Screenshot

See the full code below, use Run Example to execute.

using GemBox.Email;
using GemBox.Email.Calendar;
using System;
using System.Linq;
using System.Text;

class Sample
{
    [STAThread]
    static void Main(string[] args)
    {
        // If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY");

        // Create new calendar
        Calendar calendar = new Calendar();

        // Create new event.
        Event e = new Event();
        e.Organizer = new MailAddress("info@gemboxsoftware.com", "GemBox Ltd");
        e.Name = "GemBox conference";
        e.Location = "152 City Road, London";
        e.Start = new DateTime(2018, 1, 10, 9, 0, 0, DateTimeKind.Utc);
        e.End = new DateTime(2018, 1, 12, 18, 0, 0, DateTimeKind.Utc);
        e.Attendees.Add(new MailAddress("invited@example.com"));

        // Create new reminder.
        Reminder reminder = new Reminder();
        reminder.ReminderAction = ReminderAction.Email;
        reminder.ReminderAttendees.Add(new MailAddress("invited@example.com"));
        reminder.TriggerBeforeStart = new TimeSpan(2,0,0,0); // Remind two days before the event

        // Add reminder to the event.
        e.Reminders.Add(reminder);

        // Add event to the calendar.
        calendar.Events.Add(e);

        // Create new task
        Task task = new Task();
        task.Organizer = new MailAddress("info@gemboxsoftware.com", "GemBox Ltd");
        task.Name = "Implement iCalendar support";
        task.Start = new DateTime(2018, 1, 1, 0, 0, 0, DateTimeKind.Utc); 
        task.Deadline = new DateTime(2018, 1, 15, 0, 0, 0, DateTimeKind.Utc);
        task.Priority = 5;
        task.Categories.Add("new format support");
        task.Attendees.Add(new MailAddress("programmer@gemboxsoftware.com"));

        // Add task to the calendar.
        calendar.Tasks.Add(task);

        calendar.Save("Save.ics");
    }
}
Imports System
Imports System.Text
Imports GemBox.Email
Imports GemBox.Email.Calendar

Module Samples

    Sub Main()

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

        ' Create new calendar
        Dim calendar As Calendar = New Calendar()

        ' Create new event.
        Dim e As [Event] = New [Event]
        e.Organizer = New MailAddress("info@gemboxsoftware.com", "GemBox Ltd")
        e.Name = "GemBox conference"
        e.Location = "152 City Road, London"
        e.Start = new DateTime(2018, 1, 10, 9, 0, 0, DateTimeKind.Utc)
        e.End = new DateTime(2018, 1, 12, 18, 0, 0, DateTimeKind.Utc)
        e.Attendees.Add(New MailAddress("invited@example.com"))

        ' Create new reminder.
        Dim reminder As Reminder = New Reminder
        reminder.ReminderAction = ReminderAction.Email
        reminder.ReminderAttendees.Add(New MailAddress("invited@example.com"))
        reminder.TriggerBeforeStart = New TimeSpan(2, 0, 0, 0) ' Remind two days before the event

        ' Add reminder to the event.
        e.Reminders.Add(reminder)

        ' Add event to the calendar.
        calendar.Events.Add(e)

        ' Create new task
        Dim task As Task = New Task
        task.Organizer = New MailAddress("info@gemboxsoftware.com", "GemBox Ltd")
        task.Name = "Implement iCalendar support"
        task.Start = new DateTime(2018, 1, 1, 0, 0, 0, DateTimeKind.Utc)
        task.Deadline = new DateTime(2018, 1, 15, 0, 0, 0, DateTimeKind.Utc)
        task.Priority = 5
        task.Categories.Add("new format support")
        task.Attendees.Add(New MailAddress("programmer@gemboxsoftware.com"))

        ' Add task to the calendar.
        calendar.Tasks.Add(task)

        calendar.Save("Save.ics")

    End Sub

End Module