HOWTO: Display Free/Busy Information from an ASP Page
ID: Q195591
|
The information in this article applies to:
-
Collaboration Data Objects (CDO), versions 1.2, 1.21
SUMMARY
This article contains code that uses Collaboration Data Objects (CDO) to
retrieve free/busy information for both individuals and members of a
distribution list. It then displays the information in an Active Server
Pages (ASP) Web page according to status by color.
NOTE: Once you log on to the Microsoft Exchange server, no special
permissions are required to view the free/busy information of another
mailbox.
MORE INFORMATION
The GetFreeBusy method has the following syntax:
strAvail = objAddressEntry.GetFreeBusy(StartTime, EndTime, Interval)
A description of each follows:
- strAvail: On successful return, contains a string indicating the Messaging user's availability for each of the time slots in the specified time period.
- objAddressEntry: Required. The AddressEntry object.
- StartTime: Required. Variant (vbDate format). Specifies the date/time of the beginning of the first time slot.
- EndTime: Required. Variant (vbDate format). Specifies the date/time of the end of the last time slot.
- Interval: Required. Long. Specifies the length of each time slot in minutes. If this parameter is less than 1, GetFreeBusy returns CdoE_INVALID_PARAMETER.
To implement this Active Server Pages Web page, you must change the
ServerName and MailboxName to the proper values and then add the
individuals or distributions lists that you want to display free/busy
information for to the Recipients collection.
Sample Code
<%@ LANGUAGE="VBSCRIPT" %>
<HTML>
<HEAD>
<TITLE>Free Busy Information</TITLE>
</HEAD>
<BODY>
<TABLE ALIGN=RIGHT BORDER>
<TH>Status<TH>Color
<TR><TD>Free<TD bgcolor=white> </TR>
<TR><TD>Tenative<TD bgcolor=lightblue> </TR>
<TR><TD>Busy<TD bgcolor=blue> </TR>
<TR><TD>Out-of-Office<TD bgcolor=purple> </TR>
</TABLE>
<P>
<%
On Error Resume Next
Const cdoDistList = 1
Dim objSession
Dim strProfileInfo
strProfileInfo = "ServerName" & vbLF & "MailboxName"
Set objSession = CreateObject("MAPI.Session")
objSession.Logon , , False, True, 0, True, strProfileInfo
Set objMessage = objSession.Outbox.Messages.Add
Set objRecips = objMessage.Recipients
' Add the users or Distribution lists that you would like to
' see free/busy information.
objRecips.Add("user1")
objRecips.Add("distList1")
For Each r In objRecips
' If it is a distribution list, do the following.
If r.AddressEntry.DisplayType = cdoDistList Then
' Get the individual members, and add them.
Set objMembers = r.AddressEntry.members
For Each mem In objMembers
objRecips.Add(mem.name)
Next
' Remove the distribution list from the recipients' collection.
r.delete
End If
Next
objRecips.Resolve
Response.Write( "<TABLE border align=center>" & vbLF _
& "<TR><TH>Name" )
' Create the column headers.
For j = 0 To 23
temp = j Mod 12
If temp = 0 Then temp= 12
Response.Write("<TH>" & temp)
Next
For Each r In objRecips
Response.Write( "<TR><TD>" & r.name )
' When checking the free/busy information, pass in the start
' date/time, end date/time, and interval in minutes.
' Get Today's date.
objDate1= Date()
' Get Tommorow's date.
objDate2= Date() + 1
' Retrieve the Free/Busy Information from between to two
' time periods.
' If the user does not have any appointments
' on their calendar GetFreeBusy will return in error.
' This error check creates a string of zeros
' representing availability.
FreeBusyInfo =r.GetFreeBusy(objDate1,objDate2,60)
If Err Then '<< The only line that is changed.
FreeBusyInfo = String(24,"0")
Err.Clear
End If
' Look at each of the time blocks returned and decide what the
' status is. Each segement will be a table cell.
For i = 1 To Len(FreeBusyInfo)
' If the person is available leave the color white.
' If the person is tenative set to the color to light blue.
' If the person has a commitment set the color to blue.
' If the person is oof set the color to purple.
Select Case Mid(FreeBusyInfo, i, 1)
Case "0"
Response.Write( "<TD bgcolor=white> " )
Case "1"
Response.Write( "<TD bgcolor=lightblue> " )
Case "2"
Response.Write( "<TD bgcolor=blue> " )
Case "3"
Response.Write( "<TD bgcolor=purple> " )
End Select
Next
' End of 1 person's data.
Response.Write( "</TR>" )
Next
Set objMessage = Nothing
objSession.Logoff
Set objSession = Nothing
%>
</BODY>
</HTML>
REFERENCES
For information about Collaboration Data Objects and Active Messaging,
please see the following article in the Microsoft Knowledge Base:
Q176916
INFO: Active Messaging and Collaboration Data Objects (CDO)
Q186753
HOWTO: Check Someone Else's Schedule for Free/Busy Information
Additional query words:
Keywords : kbdocfix kbASP kbCDO120 kbCDO121 kbOLEMsg kbGrpMsg kbDSupport
Version : WINDOWS:1.2,1.21
Platform : WINDOWS
Issue type : kbhowto