Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


Creating Clickable Appointments-4 : Page 4




How to Help Your Business Become an AI Early Adopter

Generating vCalendar Formats on the Fly
Remember, our GetVCS.asp page expects one argument (id) passed via the query string—this indicates the event id for the event we need a vCalendar for. Our ASP page therefore accesses the same event details as our event-listing page and dumps the content of a single event to the browser in a vCalendar format.

Within our ASP page, we obtain the value of our event id from the Request object and make sure it is not a blank value.

Dim mlngEventID mlngEventID = Request("id") If mlngEventID = "" Then Response.Write "No Event ID found. Unable to Proceed" Response.End End if

We then obtain a recordset containing the event details for the event id provided to us:

Dim strSQL, objRS strSQL = "Select * from tblEvents where Event_ID = " & mlngEventID set objRS = GetRecordSet(strConnString, strSQL)

The above code uses a custom function GetRecordSet that accepts a connection string to a database and a valid SQL statement and returns a recordset object containing the results.

We then build our vCalendar format from the recordset data:

Dim strvCalendar strvCalendar = BuildVCalendar(objRS)

"BuildVCalendar" is a user-defined function that we write within our ASP page that accepts a recordset object and returns the event data in a vCalendar format. returned string. We next send the returned string back to the browser, informing the browser that we are sending vCalendar data:

Response.ContentType = "text/x-vCalendar" Response.AddHeader "Content-Disposition", _ "filename=Event" & mlngEventID & ".vcs;" Response.Write strvCalendar Response.End

The first line tells the browser that the content being sent is of type "text/x-vcalendar". This allows the browser to prepare the application to accept the content. The second line tells the browser the name of the file being sent (EventXX.vcs where XX = event id). Finally, we send our vCalendar format string and end our application.

The "BuildVCalendar" routine takes the values from the recordset and builds a long string in the vCalendar format:

Function BuildVCalendar(byval objRS) ' - configure our Time Zone Factor. Set this to the value ' - that needs to be added/subtracted from the date/time ' - to convert the event date/time to GMT time ' - base it on your Web Server's time zone ' - In my case, Eastern Time is 5.5 hours behind GMT so ' - to get GMT, I need to add 5.5 hours CONST TIMEZ0NE_FACTOR = +5.5 Dim dtStart, dtEnd, strSubject, strLocation, strDesc ' -- Assuming Event_Begin_Date and Event_End_Date hold ' -- Date and Time values dtStart = DateAdd("h",TIMEZONE_FACTOR, objRS("Event_Begin_Date")) dtEnd = DateAdd("h",TIMEZONE_FACTOR, objRS("Event_End_Date")) ' -- Format it properly as YYYYMMDDThhmmssZ dtStart = Right("0000", Year(dtStart), 4) & _ Right("00" & Month(dtStart), 2) & _ Right("00" & Day(dtStart), 2) & _ "T" & _ Right("00" & Hour(dtStart), 2) & _ Right("00" & Minute(dtStart), 2) & _ Right("00" & Second(dtStart), 2) & _ "Z" dtEnd = Right("0000", Year(dtEnd), 4) & _ Right("00" & Month(dtEnd), 2) & _ Right("00" & Day(dtEnd), 2) & _ "T" & _ Right("00" & Hour(dtEnd), 2) & _ Right("00" & Minute(dtEnd), 2) & _ Right("00" & Second(dtEnd), 2) & _ "Z" ' -- strSubject = objRS("Event_Title") strLocation = objRS("Event_Location") strDesc = objRS("Event_Description") BuildVCalendar = _ "BEGIN:VCALENDAR" & vbCrlf & _ "VERSION:1.0" & vbCrlf & _ "BEGIN: VEVENT" & vbCrlf & _ "DTStart:" & dtStart & vbCrlf & _ "DTEnd:" & dtEnd & vbCrlf & _ "SUMMARY;ENCODING=QUOTED-PRINTABLE:" & strSubject & vbCrlf & _ "DESCRIPTION;ENCODING=QUOTED-PRINTABLE:" & strDescription & vbCrlf & _ "Location;ENCODING=QUOTED-PRINTABLE:" & strLocation & vbCrlf & _ "UID:" & objRS("Event_ID") & dtStart & strSubject & vbCrlf & _ "PRIORITY:3" & vbCrlf & _ "End:VEVENT" & vbCrlf & _ "End:VCALENDAR" & vbCrlf End Function

And there you have it. You now have a generic utility ASP page that can return any event in a vCalendar format. You can use it within one or more Web apps with minor changes.

Rama Ramachandran is the Vice President of Technology with Imperium Solutions and is a Microsoft Certified Solution Developer and Site Builder. He has extensive experience with building database systems and has co-authored several books including "Professional Visual InterDev 6 Programming" and "Professional Data Access" (Wrox). Rama teaches Visual Basic and Web development at Fairfield University and University of Connecticut.
Comment and Contribute






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



Thanks for your registration, follow us on our social networks to keep up-to-date