Tutorial: ASP.NET iCalendar Export (Outlook, Google Calendar, Mac OS X Calendar)

This tutorial shows how to create a complex event calendar UI with day, week, and month views. Includes PHP sample code.
Sep 21, 2015
asp.net icalendar export outlook google calendar mac os x

Features

  • Features
  • Export calendar events in iCalendar format
  • Subscribe using Microsoft Outlook
  • Subscribe using Mac OS X Calendar
  • Subscribe using Google Calendar
  • Import downloaded .ics file
  • Visual Studio 2015 sample project with source code
  • Includes the open-source DayPilot Lite for ASP.NET WebForms
  • Available under Apache Software License 2.0 (open-source)

Source code of the tutorial is available for download.

Sample Code: Generating Calendar Data in iCalendar Format

This example shows how to create an iCalendar feed using C#:

protected void Page_Load(object sender, EventArgs e)
{
  iCalendar iCal = new iCalendar();

  DataTable events = Db.LoadEvents(DateTime.Today.AddDays(-7), DateTime.MaxValue);

  foreach (DataRow dr in events.Rows)
  {
      Event evt = iCal.Create<Event>();
     
      evt.Start = new iCalDateTime((DateTime) dr["EventStart"]);
      evt.End = new iCalDateTime((DateTime) dr["EventEnd"]);
      evt.Description = (string)dr["EventName"];
  }

  iCalendarSerializer serializer = new iCalendarSerializer();
  string output = serializer.SerializeToString(iCal);

  Response.ContentType = "text/calendar";
  Response.Write(output);
  Response.End();

}