Outlook Appointments, ASP and vCalendar Page 3

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


vCalendar and ASP

Now comes the fun part ... seeing it work!

Below is posted the text of the ASP page, but due to difficulties with displaying ASP code within an ASP page, I suggest that you download the code and use that copy of the page instead of trying to copy and paste the code below.

The page is mostly self-explanatory for those familiar with ASP. In a nutshell, it draws several input boxes on the screen that collect the information we want in our appointment item: Start, End, Subject, Location and Description. The user is also asked for a directory (on the server) where the file should be created. Of course this wouldn't be done in production, but I included it in the ASP code since it is necessary for the VB Class, and must be provided somewhere. It could be hard-coded and in my example, defaults to "C:\" if the user provides nothing.

The most important part of the code is where the VCSWrap.ApptItem class is instantiated, its properties are set and the CreateVCSEvent method is invoked. The vCalendar file is created and its path is passed to the Response.Redirect method of the ASP page. Since a vcs file cannot be displayed, it is opened automatically. If the user's PIM application is designed to process .vcs files, as Outlook is, an appointment item is opened with all the properties set from our web page.

        Dim objVCal, VCalFile
        Set objVcal = Server.CreateObject("VCalWrap.ApptItem")

        With objVCal
            .DTStart = DTStart
            .DTEnd = DTEnd
            .Subject = Subject
            .Location = Location
            .Description = Description
            .OutputFilePath = OutputFilePath
            .TimeZoneBias = -7
            .CreateVCSEvent
            VCalFile = .VCalFile
        End With
        Response.Redirect(VCalFile)

Conclusion

Some of you may not immediately see the benefits of this technology while others are getting excited and anxious to try out the code. Addmittedly, I was not at first convinced that vCalendar could add value to our web application. Then, our ASP developer put together code similar to the above and did a demo for the sales and marketing guys. Their excitement made up for my lack of it and I decided to give the idea a second look. Although it doesn't solve every problem, it does make it easy to "calendar-enable" your web application ... and it's cool to play with!


********* BEGIN ASP PAGE CODE HERE ************************************************ 

 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">  
 <HTML><HEAD>  
 <META content="text/html; charset=unicode" http-equiv=Content-Type>  
 <META content="MSHTML 5.00.3207.2500" name=GENERATOR></HEAD>  
 <BODY>  
 <FORM method=post action="TestVCal.asp" name="VCal">  
 <pre>  
 <P align=center><FONT face=Verdana size=4>  
     <STRONG>VCalendar Test Page</STRONG></FONT></P>  
 <%  
     Dim DTStart, DTEnd, Subject, Location  
     Dim Description, OutputFilePath  
     Dim fMissingCriticalData, strMsg, Pass  
    DTStart = Request.Form("DTStart")  
    DTEnd = Request.Form("DTEnd")   
    Subject = Request.Form("Subject")  
    Location = Request.Form("Location")  
    Description = Request.Form("Description")  
    OutputFilePath = Request.Form("OutputFilePath")  
    Pass = Request.Form("Pass")  
     fMissingCriticalData=0  
    strMsg = ""  
     ' Put some default values in input boxes  
    If Len(Subject) = 0 Then Subject = "Undetermined"  
    If Len(Location) = 0 Then Location = "Undetermined"  
    If Len(Description) = 0 Then Description = "Undetermined"  
    If Len(OutputFilePath) = 0 Then  OutputFilePath ="C:\"  
    If Len(Pass) = 0 Then Pass = 0  
    If Pass > 0 Then  
        If Len(DTStart)= 0 OR Not IsDate(DTStart) Then   
       fMissingCriticalData=1  
       strMsg = strMsg & "<Font color=red>Missing valid start date and time.</Font><BR>"  
        End If  
        If Len(DTEnd)= 0 OR Not IsDate(DTEnd) Then   
       fMissingCriticalData=1  
       strMsg = strMsg & "<Font color=red>Missing valid end date and time.</Font><BR>"  
        End If  
    Else  
        strMsg = "<B>Provide the following information to create the appointment item.</b>"  
    End If  
    If fMissingCriticalData=1 or pass=0 Then   
       Response.Write(strMsg)  
 %&gt  
       <FONT face=Veranda size=3>  
          <INPUT id=txtPass name=Pass style="VISIBILITY: hidden" value="<%=Pass + 1 %&gt">  
       <TABLE Border=0 align=center>  
         <tr>  
            <td>Start Date and Time:</td>  
            <td><INPUT align=right id=txtDTStart name=DTStart value=<%=DTStart %&gt</td>  
            <td>(Format:  mm/dd/yy hh:nn am/pm)</td>  
         </tr>  
         <tr>  
            <td>End Date and Time:</td>  
            <td><INPUT align=right id=txtDTEnd name=DTEnd value=<%=DTEnd %&gt</td>  
            <td>(Format:  mm/dd/yy hh:nn am/pm)</td>  
         </tr>  
         <tr>  
            <td>Subject:</td>  
            <td><INPUT align=right id=txtSubject name=Subject value=<%=Subject %&gt></td>  
            <td></td>  
         </tr>  
         <tr>  
            <td>Location:</td>  
            <td><INPUT align=right id=txtLocation name=Location value=<%=Location %&gt></td>  
            <td></td>  
         </tr>  
         <tr>  
            <td>Description:</td>  
            <td><INPUT align=right id=txtDescription name=Description value=<%=Description %&gt></td>  
            <td></td>  
         </tr>  
         <tr>  
            <td>Output File Path:</td>  
            <td><INPUT align=right id=txtOutputFilePath name=OutputFilePath value=<%=OutputFilePath %&gt></td>  
            <td></td>  
         </tr>  
         <tr>  
            <td></td>  
            <td><INPUT id=submit1 name=submit1 type=submit value=Submit></td>  
            <td><INPUT id=reset1 name=reset1 type=reset value=Reset></td>  
         </tr>  
       </FONT>  
       </TABLE>  
 <%  
    Else  
       If Len(Subject) = 0 Then Subject = "(No Subject Given)"  
       If Len(Location) = 0 Then Location = "(No Location Given)"  
       If Len(Description) = 0 Then Description = "(No Description Given)"  
       Dim objVCal, VCalFile  
       Set objVcal = Server.CreateObject("VCalWrap.ApptItem")  
       With objVCal  
          .DTStart = DTStart  
          .DTEnd = DTEnd  
          .Subject = Subject  
          .Location = Location  
          .Description = Description  
          .OutputFilePath = OutputFilePath  
          .TimeZoneBias = -7  
          .CreateVCSEvent  
          VCalFile = .VCalFile  
       End With  
       Response.Redirect(VCalFile)  
   
    End If  
  %gt  
 </FORM>  
 </BODY></HTML>  
 			

Page 3 of 3


Comment and Contribute

Your name/nickname

Your email

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