Shawn's Blog

a hair-band lovin', techni-junkie's banter about… whatever.

Create an add to Outlook Calendar option on your website

Posted on | November 13, 2009 | 1 Comment

I was recently asked if I could create an add to Outlook option on a company website.  Searching for code on how to do this, I came up short, as many people were looking to do this, but in the end, the result was people saving the Outlook calendar event to a file, and linking to that.

Since I need to create the event dynamically, that really was not an option.  Basically, what you need to do is create an “.ics” file, which Outlook can import.  Ironically,  exporting a file from Outlook 2007 as an ICS file would not import back into Outlook without modification.  The code below will create the file that you can then link to in your own code. You will need to ensure that you have write permissions set in the folder where the file will be created.

Here is how I obtained the result I was looking for in ASP. 

Note:  The times for the events default to 12:00am in this coding, as we do not track times in our DB.  If you need to modify the time settings as well, you will need to adjust the DTSTART & DTEND lines.  You can export an Outlook entry as an ICS file and look at it in Notepad to see how to format the times. Some of the variables were created outside of this coding as well, but this will give you an idea on how to create the file.

<%

modifiedDate=year(date()) &month(date()) & day(date())
start=year(startDate) &month(startDate) & day(startDate)
finish=year(endDate) &month(endDate) & day(endDate)

dim fsys,fname
set fsys=Server.CreateObject(“Scripting.FileSystemObject”)
set fname=fsys.CreateTextFile(“C:\calendar\” & CourseCode & “.ics”,true)
fname.WriteLine(“BEGIN:VCALENDAR”)
fname.WriteLine(“PRODID:-//Microsoft Corporation//Outlook 12.0 MIMEDIR//EN”)
fname.WriteLine(“METHOD:PUBLISH”)
fname.WriteLine(“X-MS-OLK-FORCEINSPECTOROPEN:TRUE”)
fname.WriteLine(“BEGIN:VEVENT”)
fname.WriteLine(“CLASS:PUBLIC”)
fname.WriteLine(“CREATED:”& modifiedDate &”T131421Z”)
fname.WriteLine(“DESCRIPTION:” & description &”\n”)
fname.WriteLine(“DTEND:” & finish & “T040000Z”)
fname.WriteLine(“DTSTAMP:” & modifiedDate & “T133125Z”)
fname.WriteLine(“DTSTART:” & start & “T040000Z”)
fname.WriteLine(“LAST-MODIFIED:” & modifiedDate & “T133125Z”)
fname.WriteLine(“LOCATION:” & Location)
fname.WriteLine(“PRIORITY:5″)
fname.WriteLine(“SEQUENCE:0″)
fname.WriteLine(“SUMMARY;LANGUAGE=en-ca:” & Title)
fname.WriteLine(“TRANSP:OPAQUE”)
fname.WriteLine(“UID:040000008200E00074C5B7101A82E00800000000A03719A74164CA01000000000000000″)
fname.WriteLine(“    0100000007288DD675F5B734887B06758AA7ACD1B”)
fname.WriteLine(“X-ALT-DESC;FMTTYPE=text/html:<!DOCTYPE HTML PUBLIC ‘-//W3C//DTD HTML 3.2//E”)
fname.WriteLine(“    N’>\n<HTML>\n<HEAD>\n<META NAME=’Generator’ CONTENT=’MS Exchange Server ve”)
fname.WriteLine(“    rsion 08.00.0681.000′>\n<TITLE></TITLE>\n</HEAD>\n<BODY>\n<!– Converted f”)
fname.WriteLine(“    rom text/rtf format –>\n\n<P DIR=LTR><SPAN LANG=’en-ca’><FONT FACE=’Calib”)
fname.WriteLine(“    ri’>” & description & “</FONT></SPAN><SPAN LANG=’en-ca”)
fname.WriteLine(“    ‘></SPAN></P>\n\n</BODY>\n</HTML>”)
fname.WriteLine(“X-MICROSOFT-CDO-BUSYSTATUS:BUSY”)
fname.WriteLine(“X-MICROSOFT-CDO-IMPORTANCE:1″)
fname.WriteLine(“X-MICROSOFT-DISALLOW-COUNTER:FALSE”)
fname.WriteLine(“X-MS-OLK-ALLOWEXTERNCHECK:TRUE”)
fname.WriteLine(“X-MS-OLK-AUTOFILLLOCATION:FALSE”)
fname.WriteLine(“X-MS-OLK-CONFTYPE:0″)
fname.WriteLine(“BEGIN:VALARM”)
fname.WriteLine(“TRIGGER:-PT20160M”)
fname.WriteLine(“ACTION:DISPLAY”)
fname.WriteLine(“DESCRIPTION:Reminder”)
fname.WriteLine(“END:VALARM”)
fname.WriteLine(“END:VEVENT”)
fname.WriteLine(“END:VCALENDAR”)
fname.Close
set fname=nothing
set fsys=nothing
%>

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • StumbleUpon

Comments

One Response to “Create an add to Outlook Calendar option on your website”

  1. Steven
    November 16th, 2009 @ 12:11 pm

    Awesome work Shawn!

    Sometimes we take you for granted, but this is great stuff!.

Leave a Reply





  • Tools