Outlook Appointments, ASP and vCalendar Page 2

By Danny Lesandrini (Send Email)
Posted May 29, 2001


The Custom VB vCalendar Class and DLL

I created a custom Visual Basic class to serve as a wraper around the process of creating the vCalendar text file. The class does limited date validation (that responsibility is left to the ASP code), but does some time zone adjustment and parses the date into a vCalendar-ready text string, prior to writing the formatted text to a .vcs file.

This class exposes only the most basic properties of the Outlook Appointment item. If more properties need to be set, you could determine the format by following the instructions on the previous page for using Outlook to create a vCalendar template and add those properties to the VB Class. Note that Property Let and Property Get procedures are used to populate the following private variables:

    Private dtmStart As Date
    Private dtmEnd As Date
    Private strLocation As String
    Private strSubject As String
    Private strDescription As String
    Private strOutputFilePath As String
    Private intTimeZoneBias As Integer

The class has only one Method which parses the variables into strings and creates the .vcs file. This method returns the path to the .vcs file as a string value. This file path is needed by the ASP page, as we will see later. Notice the relatively simple code involved with this proces:

    Public Function CreateVCSEvent() As Boolean
        On Error Resume Next
    
        Dim strStartDate As String
        Dim strEndDate As String
        Dim strToday As String
        Dim iFileNumber As Integer
        Dim strVCalFile As String
    
        ' VCS uses GMT so all values must be adjusted according to
        ' your Time Zone.  Mountain Time (Denver) is -7
        ' TimeZone Offset from GMT is always Negative.  Make it positive.
        intTimeZoneBias = intTimeZoneBias * (-1)
        
        dtmStart = DateAdd("h", intTimeZoneBias, dtmStart)
        dtmEnd = DateAdd("h", intTimeZoneBias, dtmEnd)
        
        ' Format user-supplied data in VCS required format.
        ' Note that the style "Hhnnss" returns time in 24-hour format.
        strStartDate = Format(dtmStart, "yyyymmdd") & "T" & Format(dtmStart, "Hhnnss")
        strEndDate = Format(dtmEnd, "yyyymmdd") & "T" & Format(dtmEnd, "Hhnnss")
        
        ' If no date was passed, for example, "8:30 am", the date defaults to 12/30/1899
        ' Since this date is of no value, test for it and convert it to the current date.
        ' (Code could also be added to handle dates passed with no TIME value.)
        If Left(strStartDate, 8) = "18991230" Then
            strToday = Format(Date, "yyyymmdd")
            strStartDate = strToday & Mid(strStartDate, 9)
        End If
    
        If Left(strEndDate, 8) = "18991230" Then
            strToday = Format(Date, "yyyymmdd")
            strEndDate = strToday & Mid(strEndDate, 9)
        End If
  
        ' Create the file based on the path provided by the user.  Use the
        ' Subject as the name of the file.
        iFileNumber = FreeFile
        If Right(strOutputFilePath, 1) = "\" Then
            strVCalFile = strOutputFilePath & strSubject & ".vcs"
        Else
            strVCalFile = strOutputFilePath & "\" & strSubject & ".vcs"
        End If

        ' Create the .vcs file.  Use the Start and End dates and Subject  as a unique UID
        Open strVCalFile For Output As #iFileNumber
    
        Print #iFileNumber, "BEGIN:VCALENDAR"
        Print #iFileNumber, "VERSION:1.0"
        Print #iFileNumber, "BEGIN: VEVENT"
        Print #iFileNumber, "DTStart:" & strStartDate
        Print #iFileNumber, "DTEnd:" & strEndDate
        Print #iFileNumber, "Location;ENCODING=QUOTED-PRINTABLE:" & strLocation
        Print #iFileNumber, "SUMMARY;ENCODING=QUOTED-PRINTABLE:" & strSubject
        Print #iFileNumber, "DESCRIPTION;ENCODING=QUOTED-PRINTABLE:" & strDescription
        Print #iFileNumber, "UID:" & strStartDate & strEndDate & strSubject
        Print #iFileNumber, "PRIORITY:3"
        Print #iFileNumber, "End:VEVENT"
        Print #iFileNumber, "End:VCALENDAR"
        
        Close #iFileNumber
		
        ' Note that more properties could easily be added
    End Function

In order for this class to be used by our ASP page, it is necessary to compile it into an Active-X dll and register it on the server. The download for this article includes a VB project with the code and an ASP page to execute it. I named the DLL VCSWrap and if you unzip the contents of the download into a folder named vCal under the C:\Inetpub\wwwroot\ directory, then you can register it with this line:
    regsvr32 C:\Inetpub\wwwroot\Vcal\VCalWrap.dll

Page 2 of 3


Comment and Contribute

Your name/nickname

Your email

(Maximum characters: 1200). You have characters left.