How to create an event using .ICS Files for Apple’s iCal or Microsoft’s Outlook

.ICS files allow you to be able to create small files that you can either include in an email campaign or link to on your website that will enable you to add, edit or even cancel events in people’s calendar without the requirement of them needing to fill out any of the details.

These files are commonly called iCal, vCalendar or iCalendar and often use various extensions such as .ics, .ical, .ifb & .icalendar

To create an event, the goal is to produce a small text file that contains the following:

BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Microsoft Corporation//Outlook 11.0 MIMEDIR//EN
BEGIN:VEVENT
UID:email@internet.com
DTSTAMP:20120101T000000Z
ORGANIZER;CN=SAU:MAILTO:SAU@skylinesaustralia.com
DTSTART:20120715T000000Z
DTEND:20120715T150000Z
SUMMARY:SAUNSW Texikhana, S.O.S. proudly supported by Unigroup Engineering
LOCATION:Nirimba Airfield/TAFE/Skidpan
DESCRIPTION:S A U N S W - Texi, Sos, 15Th July 2012
END:VEVENT
END:VCALENDAR

Breaking this code down, it’s quite simple to see what each line is doing:

BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Microsoft Corporation//Outlook 11.0 MIMEDIR//EN

These 3 lines of code tell the receiving program what the following content is buy using the BEGIN code “this is a vCalendar file”. It then used VERSION to indicated the context of the following code. The PRODID is simply the name of the program that created the file and you can basically enter in what ever string you want in this section.

BEGIN:VEVENT

Indicated that this is a EVENT file and it is the beginning of the even information.

UID:email@internet.com

Is a unique identifier for this file. It is used so that you can control future actions of this even easily.

DTSTAMP:20120101T000000Z

When the file was created. (NOTE: all time are strictly 24H GMT)

ORGANIZER;CN=SAU:MAILTO:SAU@skylinesaustralia.com

Who the organiser of this event.

DTSTART:20120715T000000Z

When the event is going to start (NOTE: all time are strictly 24H GMT)

DTEND:20120715T150000Z

When the event is going to end (NOTE: all time are strictly24H GMT)

SUMMARY:SAUNSW Texikhana, S.O.S. proudly supported by Unigroup Engineering

The summary will appear in the small field in outlook and will be the content that shows when the user is viewing the calendar one of the various overview modes.

LOCATION:Nirimba Airfield/TAFE/Skidpan

Set the location of the event.

DESCRIPTION:S A U N S W - Texi, Sos, 15Th July 2012

The description is the bulk of the event content. It is where you would put all the finer details about the event like EST costs, what to bring etc.

END:VEVENT

Let the program know this is now the end the event content.

END:VCALENDAR

Let the program know this is now the end the .ics file.

Advanced

This all seems pretty basic. However, there are numerous amounts of additional commands you can include into an .ICS file that can control a lot more actions:

In an event you can inclued a VALARM command that will allow you cause the calendar application to alert the user in advanced of the event coming up.

Entering the following command inside the VEVENT will enable this

BEGIN:VALARM
TRIGGER:19980403T120000
ACTION:DISPLAY
DESCRIPTION:Reminder
END:VALARM

This is again pretty straight forward, We have a BEGIN and END tag to describe the content contained is a VALARM, a TRIGGER which is the time to perform the reminder in YYYMMDD-T-HHMMSS (24H GMT time once again), an ACTION tag which allows you to set what to do and a DESCRIPTION where you can set what data to show the user when the reminder appears.

Updating an event

For sending an UPDATE for an event the UID should match the original UID and you should add the following tag inside theBEGIN:VEVENT in the new file

SEQUENCE:x

Where x = the upper most sequence used in the history of the event.

Cancelling an event

You can also cancel an event using the same method. Te following tags will allow the cancellation and a status message to show why it was cancelled

METHOD:CANCEL
STATUS:CANCELLED

Dynamic Content

If you know a scripting language such as ASP or PHP you can create these file dynamically. To do this all you need to d is change the header’s on your .asp or .php file so that you tell your users browser that it is a .ICS file and that it should open it in the default calendar application.

PHP:

header("Content-Type: text/x-vCalendar");
header("Content-Disposition: inline; filename=july-skids.vcs");

Now you can script your file so that each area is dynamically created.

EDIT

Now with ASP headers

'construct the headers for the file to open as a vcal
Response.ContentType = "text/x-vCalendar"
Response.Expires = -1
Response.Buffer = True
Response.Clear
Response.AddHeader "Content-Disposition", "filename=vcal.vcs;"
Response.Write strFileContent