Menu

Want to work with us? We're on the lookout for a UX/UI Designer and Digital Project Manager.

We're hiring

How To Generate an Outlook vCalendar File from ASP.NET (VB)

Web Bureau


21 August 2013 by Web Bureau

We recently had to add a link button to a client site whereby users could click on it and download a vCalendar file to their Outlook Calendar.

Here is a code snippet of how we got this to work. One thing to bear in mind is setting the timezone and any daylight saving rules. Without these, the downloaded appointment file may have the wrong times by being out plus or minus one hour.

Our sample here uses GMT and British Summer Time

sbICSFile.AppendLine("BEGIN:VCALENDAR")
sbICSFile.AppendLine("VERSION:2.0")
sbICSFile.AppendLine("METHOD:PUBLISH")
sbICSFile.AppendLine("X-WR-TIMEZONE:Europe/London")
sbICSFile.AppendLine("BEGIN:VTIMEZONE")
sbICSFile.AppendLine("TZID:Europe/London")
sbICSFile.AppendLine("X-LIC-LOCATION:Europe/London")
sbICSFile.AppendLine("BEGIN:DAYLIGHT")
sbICSFile.AppendLine("TZOFFSETFROM:+0000")
sbICSFile.AppendLine("TZOFFSETTO:+0100")
sbICSFile.AppendLine("TZNAME:BST")
sbICSFile.AppendLine("DTSTART:19700329T010000")
sbICSFile.AppendLine("RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU")
sbICSFile.AppendLine("END:DAYLIGHT")
sbICSFile.AppendLine("BEGIN:STANDARD")
sbICSFile.AppendLine("TZOFFSETFROM:+0100")
sbICSFile.AppendLine("TZOFFSETTO:+0000")
sbICSFile.AppendLine("TZNAME:GMT")
sbICSFile.AppendLine("DTSTART:19701025T020000")
sbICSFile.AppendLine("RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU")
sbICSFile.AppendLine("END:STANDARD")
sbICSFile.AppendLine("END:VTIMEZONE")
sbICSFile.AppendLine("BEGIN:VEVENT")
sbICSFile.AppendLine("CATEGORIES:Events")
sbICSFile.AppendLine("DTSTART;TZID=Europe/London:" & str_StartDate & vbCr & vbLf)
sbICSFile.AppendLine("DTEND;TZID=Europe/London:" & str_EndDate & vbCr & vbLf)
sbICSFile.AppendLine("SUMMARY:" & pTitle & vbCr & vbLf)
sbICSFile.AppendLine("LOCATION:" & pLocation & vbCr & vbLf)
sbICSFile.AppendLine("METHOD:")
sbICSFile.AppendLine("STATUS:")
sbICSFile.AppendLine("SEQUENCE:0")
sbICSFile.AppendLine("DESCRIPTION:")
sbICSFile.AppendLine("END:VEVENT")
sbICSFile.AppendLine("END:VCALENDAR")

Response.ContentType = "text/calendar"
Response.AddHeader("content-disposition", _
"attachment; filename=CalendarEvent.ics")
Response.Write(sbICSFile)
Response.End()

Grow your businessStart a project with us today.