8000 Home · ical-org/ical.net Wiki · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
axunonb edited this page Jun 14, 2025 · 11 revisions
Logo

Introduction to iCalendar and iCal.NET

iCalendar is a widely used standard (RFC 5545) for exchanging calendar and scheduling information such as events, to-dos, journal entries, and free/busy information. It is supported by most major calendar applications and services, making it a common format for interoperability.

iCal.NET is a .NET library that provides a simple and flexible API for creating, parsing, and serializing iCalendar data. It is useful for:

  • Generating .ics files for calendar events and schedules.
  • Parsing existing iCalendar data from files or streams.
  • Managing recurring events, time zones, and reminders.
  • Integrating calendar functionality into .NET applications.

Getting Started with iCal.NET

Create a simple calendar event

var date = new CalDateTime(2024, 10, 15, 11, 0, 0);
var calendarEvent = new CalendarEvent
{
    // If Name property is used, it MUST be RFC 5545 compliant
    Summary = "Event Title", // Should always be present
    Description = "Event description goes here", // optional
    Start = date,
    End = date.AddHours(2),
};

var calendar = new Ical.Net.Calendar();
calendar.Events.Add(calendarEvent);
calendar.AddTimeZone(new VTimeZone("Europe/Copenhagen")); // TZ should be added
var serializer = new CalendarSerializer();
var serializedCalendar = serializer.SerializeToString(calendar);
Console.WriteLine(serializedCalendar);

Output (DTSTAMP and UID will differ):

BEGIN:VCALENDAR
PRODID:-//github.com/ical-org/ical.net//NONSGML ical.net 5.0.0//EN
VERSION:2.0
BEGIN:VEVENT
DESCRIPTION:Event description goes here
DTEND:20241015T130000
DTSTAMP:20241015T110000
DTSTART:20241015T110000
SEQUENCE:0
SUMMARY:Event Title
UID:a4982558-e1aa-412e-8610-e2102fe0e616
END:VEVENT
BEGIN:VTIMEZONE
TZID:Europe/Copenhagen
X-LIC-LOCATION:Europe/Copenhagen
END:VTIMEZONE
END:VCALENDAR

Create a calendar with a recurring event

var now = CalDateTime.Now;
var later = now.AddHours(1);

// Repeat daily for 5 days
var rrule = new RecurrencePattern(FrequencyType.Daily, 1) { Count = 5 };

var e = new CalendarEvent
{
    Start = now,
    End = later,
    RecurrenceRules = new List<RecurrencePattern> { rrule },
};

var calendar = new Calendar();
calendar.Events.Add(e);

var serializer = new CalendarSerializer();
var serializedCalendar = serializer.SerializeToString(calendar);

Output:

BEGIN: VCALENDAR
VERSION:2.0
PRODID: -//github.com/ical-org/ical.net//NONSGML ical.net 5.0.0//EN
BEGIN:VEVENT
DTEND:20160704T172520
DTSTAMP:20160704T162520
DTSTART:20160704T162520
RRULE:FREQ=DAILY;COUNT=5
SEQUENCE: 0
UID: f4693a88-0a57-4761-b949-8822b8a507d2
END:VEVENT
END:VCALENDAR
Clone this wiki locally
0