Skip to main content

Feeding the simple Html Calendar with Exoledb

Man this was a lot harder then I expected it would be, When it comes to representing time in anything you are really starting to deal with a different dimension (I think time is the third dimension). Eg you can select all the records in a calendar with the startdate greater then the first of the month and a startdate less then the end of the month but this is going to miss all multi-day appointments. Also in my example say I wanted to know if there where any appointments that where on the 5th then just looking at the start date of an appointment wouldn't necessarily tell me this because I could have a multiday event that started on the 4th and finished on the 6th. The other problem i faced is i wanted to show all the days where there was some appointments scheduled as bold and clickable trying to do this you also run into the same problem where appointments span Multiple days (Also a lot of advanced aggregate functions aren't available in Exoledb).

To solve this problem my solution was to use a sliding time window, so to get all the appointments for the month I had to query for all appointments with a enddate greater then the 1st of the month and a startdate that was less then the 1st day of next month. To work out if there were any appointments on each particular day I did a 31 repetition for next loop using a time window that spanned a 1 day and re-filtered the recordset for each repitition. (the logic sounds a bit weird but its one of those things you really need to think about but it does work and only requires one query of the Exchange Server). Then I just reused the array in the for next loop that generated the calendar

To feed my Asp calendar I packaged up the Exoledb code into a WSC com object and then created a wrapper that runs under an account that had rights to the calendar I wanted this page to access. I also created some click thoughs that would display the days appointments in a table on the right of the page. This still needs a fair bit of work but it works fine at the moment. I would have prefered to maybe use some inline xml so i didn't have to requery Exchange everytime i looked at a different day.

WSC object ..


<?xml version="1.0"?>
<component>

<registration
description="calfeed"
progid="calfeed.WSC"
version="1.00"
classid="{4414f884-d473-401a-8357-b899f3de8f31}"
>
</registration>

<public>
<method name="mailbox">
<PARAMETER name="MBname"/>
</method>
</public>

<implements type="ASP" id="ASP"/>

<script language="VBScript">
<![CDATA[

function mailbox(MBname)

set shell = createobject("wscript.shell")
strValueName = "HKLM\SYSTEM\CurrentControlSet\Control\TimeZoneInformation\ActiveTimeBias"
minTimeOffset = shell.regread(strValueName)
toffset = datediff("h",DateAdd("n", minTimeOffset, now()),now())
dtListFrom = DateAdd("n", minTimeOffset, now())
gmttime = dateadd("h",toffset,now())
dtListTo = isodateit(dateserial(year(now()),month(dateadd("m",1,now())),1)& " " & timeserial(0,0,0))
dtListFrom = isodateit(dateserial(year(now()),month(now()),1) & " " & timeserial(0,0,0))
Set Rs = CreateObject("ADODB.Recordset")
set Rec = CreateObject("ADODB.Record")
Set Conn = CreateObject("ADODB.Connection")
CalendarURL = "http://yourserver/exchange/" & MBname & "/calendar"
Conn.Provider = "ExOLEDB.DataSource"
Rec.Open CalendarURL
Set Rs.ActiveConnection = Rec.ActiveConnection
Rs.Source = "SELECT ""DAV:href"", " & _
" ""urn:schemas:httpmail:subject"", " & _
" ""urn:schemas:calendar:dtstart"", " & _
" ""urn:schemas:calendar:dtend"", " & _
" ""urn:schemas:calendar:organizer"", " & _
" ""urn:schemas:calendar:location"", " & _
" ""DAV:contentclass"" " & _
"FROM scope('shallow traversal of """ & CalendarURL & """') " & _
"WHERE (""urn:schemas:calendar:dtend"" > CAST(""" & dtListFrom & """ as 'dateTime'))" & _
"AND (""urn:schemas:calendar:dtstart"" < CAST(""" & dtListTo & """ as 'dateTime'))"& _
" AND ""DAV:contentclass"" = 'urn:content-classes:appointment'" & _
"ORDER BY ""urn:schemas:calendar:dtstart"" ASC"

Rs.CursorLocation = 3 'adUseServer = 2, adUseClient = 3
Rs.CursorType = 3
Rs.Open
set mailbox = Rs
end function

function isodateit(datetocon)
strDateTime = year(datetocon) & "-"
if (Month(datetocon) < 10) then strDateTime = strDateTime & "0"
strDateTime = strDateTime & Month(datetocon) & "-"
if (Day(datetocon) < 10) then strDateTime = strDateTime & "0"
strDateTime = strDateTime & Day(datetocon) & "T" & formatdatetime(datetocon,4) &":00Z"
isodateit = strDateTime
end function


]]>
</script>

Calendar ASP page ....
<%
CD = request.querystring("cday")
set cfeed = createobject("calfeed.WSC")
set rs = cfeed.mailbox("yourmailbox")
set shell = createobject("wscript.shell")
strValueName = "HKLM\SYSTEM\CurrentControlSet\Control\TimeZoneInformation\ActiveTimeBias"
minTimeOffset = shell.regread(strValueName)
toffset = datediff("h",DateAdd("n", minTimeOffset, now()),now())
dtListFrom = DateAdd("n", minTimeOffset, now())
redim myarray(3,31)
for i = 1 to 31
rs.filter = "urn:schemas:calendar:dtend > '" & dateadd("h",-toffset,dateserial(year(now()),month(now()),i))
& "' and urn:schemas:calendar:dtstart < '" & dateadd("h",-toffset,dateserial(year(now()),month(now()),i+1)) & "'"
myarray(1,i) = rs.recordcount
myarray(2,i) = dateadd("h",-toffset,dateserial(year(now()),month(now()),i))
myarray(3,i) = dateadd("h",-toffset,dateserial(year(now()),month(now()),i+1))
next
rs.filter = ""
%>
<html>

<head>
<meta name="GENERATOR" content="Microsoft FrontPage 6.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>New Page 1</title>
</head>

<body>

<br>
<table border="1" cellspacing="1" width="100%">
<tr>
<td width="151"><table border="0" id="table1" cellpadding="2" width="147">
<tr><b><% response.write "<td style=""padding: 0"" width=""112""
align=""center"" colspan=""7""><b><font face=""Arial"" color=""#000080"">" &
monthname(month(now())) & " " & Year(now()) &"</td>"
%></font></b> </tr>
<tr>
<td style="border-bottom-style: solid; padding: 0" width="16" align="center">
S</td>
<td style="border-bottom-style: solid; padding: 0" width="16" align="center">
M</td>
<td style="border-bottom-style: solid; padding: 0" width="16" align="center">
T</td>
<td style="border-bottom-style: solid; padding: 0" width="16" align="center">
W</td>
<td style="border-bottom-style: solid; padding: 0" width="16" align="center">
T</td>
<td style="border-bottom-style: solid; padding: 0" width="16" align="center">
F</td>
<td style="border-bottom-style: solid; padding: 0" width="16" align="center">
S</td>
</tr>
<%
cdatefday = cdate(dateserial(year(now()),month(now()),"1"))
sday = weekday(cdatefday)
cmonth = month(now())
for x = 1 to 6
response.write "<tr>"
for i = 1 to 7
if cmonth = month(cdatefday) then
if sday =< i then
sday = 0
if myarray(1,day(cdatefday)) = 0 then
response.write "<td style=""padding: 0"" width=""16"" align=""center"">" &
day(cdatefday) & "</td>"
else
response.write "<td style=""padding: 0"" width=""16"" align=""center""><a
href=""caltest2.asp?cday=" & day(cdatefday) & """><b>" & day(cdatefday) & "</a></b></td>"
end if
cdatefday = dateadd("d",1,cdatefday)
else
response.write "<td style=""padding: 0"" width=""16"" align=""center""> </td>"

end if
else
response.write "<td style=""padding: 0"" width=""16"" align=""center""> </td>"

end if
next
response.write "</tr>"
next

%></td>
<td>&nbsp;</td>
</tr>
</table>
<td width="617"><table border="0" cellspacing="0" width="100%" id="table2" cellpadding="0"><tr>
<td width="154"><B>Start Date</B></td>
<td width="154"><B>End Date</B></td>
<td><B>Subject</B></td>
</tr>
<% If CD <> "" then
rs.filter = "urn:schemas:calendar:dtend > '" &
dateadd("h",-toffset,dateserial(year(now()),month(now()),CD)) & "' and urn:schemas:calendar:dtstart < '" & dateadd("h",-toffset,dateserial(year(now()),month(now()),CD+1)) & "'"
end if
while not rs.eof
response.write "<tr>" & vbcrlf
response.write "<td width=""154"">" & dateadd("h",toffset,rs.fields("urn:schemas:calendar:dtstart")) & "</td>" & vbcrlf
response.write "<td width=""154"">" &
dateadd("h",toffset,rs.fields("urn:schemas:calendar:dtend")) & "</td>" & vbcrlf
response.write "<td>" & rs.fields("urn:schemas:httpmail:subject") & "</td>" & vbcrlf
response.write "</tr>" & vbcrlf
rs.movenext
wend
%>
</table>



Popular posts from this blog

The MailboxConcurrency limit and using Batching in the Microsoft Graph API

If your getting an error such as Application is over its MailboxConcurrency limit while using the Microsoft Graph API this post may help you understand why. Background   The Mailbox  concurrency limit when your using the Graph API is 4 as per https://docs.microsoft.com/en-us/graph/throttling#outlook-service-limits . This is evaluated for each app ID and mailbox combination so this means you can have different apps running under the same credentials and the poor behavior of one won't cause the other to be throttled. If you compared that to EWS you could have up to 27 concurrent connections but they are shared across all apps on a first come first served basis. Batching Batching in the Graph API is a way of combining multiple requests into a single HTTP request. Batching in the Exchange Mail API's EWS and MAPI has been around for a long time and its common, for email Apps to process large numbers of smaller items for a variety of reasons.  Batching in the Gr...

Exporting and Uploading Mailbox Items using Exchange Web Services using the new ExportItems and UploadItems operations in Exchange 2010 SP1

Two new EWS Operations ExportItems and UploadItems where introduced in Exchange 2010 SP1 that allowed you to do a number of useful things that where previously not possible using Exchange Web Services. Any object that Exchange stores is basically a collection of properties for example a message object is a collection of Message properties, Recipient properties and Attachment properties with a few meta properties that describe the underlying storage thrown in. Normally when using EWS you can access these properties in a number of a ways eg one example is using the strongly type objects such as emailmessage that presents the underlying properties in an intuitive way that's easy to use. Another way is using Extended Properties to access the underlying properties directly. However previously in EWS there was no method to access every property of a message hence there is no way to export or import an item and maintain full fidelity of every property on that item (you could export the...

EWS Create Mailbox folder Powershell module for Exchange and Office365 Mailboxes

This is a rollup post for a couple of scripts I've posted in the past for creating folders using EWS in an Exchange OnPremise or Exchange online Cloud mailbox. It can do the following Create a Folder in the Root of the Mailbox Create-Folder -Mailboxname mailbox@domain.com -NewFolderName test Create a Folder as a SubFolder of the Inbox Create-Folder -Mailboxname mailbox@domain.com -NewFolderName test -ParentFolder '\Inbox' Create a Folder as a SubFolder of the Inbox using EWS Impersonation Create-Folder -Mailboxname mailbox@domain.com -NewFolderName test -ParentFolder '\Inbox' -useImpersonation Create a new Contacts Folder as a SubFolder of the Mailboxes Contacts Folder Create-Folder -Mailboxname mailbox@domain.com -NewFolderName test -ParentFolder '\Contacts' -FolderClass IPF.Contact Create a new Calendar Folder as a SubFolder of the Mailboxes Calendar Folder Create-Folder -Mailboxname mailbox@domain.com -NewFolderName test -Parent...
All sample scripts and source code is provided by for illustrative purposes only. All examples are untested in different environments and therefore, I cannot guarantee or imply reliability, serviceability, or function of these programs.

All code contained herein is provided to you "AS IS" without any warranties of any kind. The implied warranties of non-infringement, merchantability and fitness for a particular purpose are expressly disclaimed.