Click here to Skip to main content
11,719,903 members (82,213 online)
Click here to Skip to main content

Outlook Team Calendar

, 3 Sep 2005 337.7K 6.9K 122
Rate this:
Please Sign up or sign in to vote.
Show your team's calendars side by side in a single web page.

Introduction

The code in this article will show you how to build a web page that can:

  • retrieve information from the Outlook calendars of your team members,
  • show this information in a single neat overview.

The code is written in VB.NET, but it can easily be converted into C# or any other language.

Configuration

Just copy all the files in the sample code to the root of an existing web site, but take care not to overwrite any of the existing files. If a file named "index.aspx" already exists, just copy the file from the sample code after renaming it to something else, e.g. "calendar.aspx". If a file named "web.config" already exists, don't overwrite it, this will destroy all the existing settings. Just open the existing "web.config" file, and add these 5 lines to the existing "AppSettings" settings.

<add key="ServerName" value="ExchangeServerName"/>
<add key="WindowsDomain" value="OURDOMAIN"/>
<add key="UserForReadingCalendars" value="ExchReader"/>
<add key="PwdForReadingCalendars" value="secret"/>
<add key="Usernames" value="Ann,Dan,Eric,Martin,Philip"/>

Then, change the value for each of these keys according to your own situation:

  1. The "ServerName" setting is the name of the exchange server on the network.
  2. The "WindowsDomain" setting is the name of the Windows domain controlling the user database.
  3. The user indicated in the key "UserForReadingCalendars" should at least have read permissions on the Outlook calendars. Each user listed in the 5th setting should grant this permission through Outlook's configuration settings. For Outlook 2003, see Share my Outlook calendar.
  4. The "PwdForReadingCalendars" is the password of the user in the key "UserForReadingCalendars".
  5. The last setting "Usernames" is a list of your team members, separated by commas. The names should be the names of their mail boxes (i.e. the logon names). These users should share their calendars to the user that was set in the 3rd setting.

How it works

The first part is to retrieve the calendars from the exchange server. There are several ways to do this:

  • ADO (ExOLEDB provider)
  • CDOEX
  • WebDAV

I chose the WebDAV method. It has one inconvenience: it's slow when there are lots of calendars to be read.

In this case, we need to create a request that will read the calendar on a particular date. This is the code that will retrieve all the events in the calendar, especially the properties: start, end, busy status, and of course: the content:

Function LookUpCalendar(ByVal Name As String, _
                ByVal dDate As DateTime) As XmlDocument 
   Dim strURL As String = _
      "http://" & _
      ConfigurationSettings.AppSettings("ServerName") & _
                          /exchange/" & Name & "/calendar/" 
   Dim strRequest As String = "<?xml version=""1.0""?>" & _
       "<g:searchrequest DAV:?? xmlns:g="">" & _
       "<g:sql>SELECT ""urn:schemas:calendar:location"", " & _
       """urn:schemas:httpmail:subject"", " & _
       """urn:schemas:calendar:dtstart"", ""urn:schemas:calendar:dtend"", " & _
       """urn:schemas:calendar:busystatus"", " & _
       """urn:schemas:calendar:instancetype"" " & _
       "FROM Scope('SHALLOW TRAVERSAL OF """ & strURL & """') " & _
       "WHERE NOT ""urn:schemas:calendar:instancetype"" = 1 " & _
       "AND ""DAV:contentclass"" = 'urn:content-classes:appointment' " & _
       "AND ""urn:schemas:calendar:dtstart"" > '" & _
       String.Format("{0:yyyy/MM/dd}", dDate) & " 00:00:00' " & _
       "AND ""urn:schemas:calendar:dtend"" < '" & _
       String.Format("{0:yyyy/MM/dd}", dDate.AddDays(1)) & " 00:00:00' " & _
       "ORDER BY ""urn:schemas:calendar:dtstart"" ASC" & _
       "</g:sql></g:searchrequest>"     
    Dim strStatusText As String = "" 
    Dim Status As Integer 
    Dim ResponseXmlDoc As XmlDocument = SendRequest("SEARCH", _
                             strURL, strRequest, strStatusText, Status) 
    'Display the results. 
    If (Status >= 200 And Status < 300) Then 
       AddInfo("Success! " & "Result = " & Status & ": " & _
                                               strStatusText, 2)
       Return ResponseXmlDoc 
    ElseIf Status = 401 Then 
       AddInfo("<BR /><FONT color=red>Permission denied!</FONT>", 2)
       AddInfo("<FONT color=red>" + 
              "Check your permissions for this item.</FONT>", 2)
    Else AddInfo("<FONT color=red>Request failed.</FONT>", 
       AddInfo("<FONT color=red>Result = " & Status & ": " & _
                                        strStatusText</FONT>

The result will be an XmlDocument object.

The function calls another function: SendRequest. This is standard code that will send the WebDAV search request:

Function SendRequest(ByVal strCommand As String, _
        ByVal strURL As String, ByVal strBody As String, _
        ByRef strStatusText As String, ByRef iStatCode As Integer) _
                                                       As XmlDocument 
    Try 
        ' Create a new CredentialCache object and fill it 
        ' with the network credentials required to access the server. 
        Dim Username As String = _
           ConfigurationSettings.AppSettings("UserForReadingCalendars") 
        Dim Password As String = _
           ConfigurationSettings.AppSettings("PwdForReadingCalendars") 
        Dim strDomain As String = _
           ConfigurationSettings.AppSettings("WindowsDomain") 
        Dim myCred As New NetworkCredential(Username, _
                                         Password, strDomain) 
        Dim myUri As System.Uri = New System.Uri(strURL) 
        Dim MyCredentialCache As New _
            CredentialCache MyCredentialCache.Add(myUri, "NTLM", myCred) 
        ' Create the HttpWebRequest object. 
        Dim objRequest As HttpWebRequest = _
                CType(WebRequest.Create(strURL), HttpWebRequest) 
        ' Add the network credentials to the request. 
        objRequest.Credentials = MyCredentialCache 
        ' Specify the method. objRequest.Method = strCommand 
        ' Set Headers objRequest.KeepAlive = True 
        objRequest.Headers.Set("Pragma", "no-cache") 
        objRequest.ContentType = "text/xml" 
        'Set the request timeout to 5 minutes 
        objRequest.Timeout = 300000 
        If (strBody.Length > 0) Then 
            ' Store the data in a byte array 
            Dim ByteQuery() As Byte = _
                   System.Text.Encoding.ASCII.GetBytes(strBody) 
            objRequest.ContentLength = ByteQuery.Length 
            Dim QueryStream As Stream = objRequest.GetRequestStream() 
            ' Write the data to be posted to the Request Stream 
            QueryStream.Write(ByteQuery, 0, ByteQuery.Length) 
            QueryStream.Close() 
         End If 
         ' Send the method request and get the response 
         ' from the server. 
         Dim objResponse As HttpWebResponse = _
               CType(objRequest.GetResponse(), HttpWebResponse) 
         ' Get the Status code iStatCode = objResponse.StatusCode 
         strStatusText = objResponse.StatusDescription 
         ' Get the XML response stream. 
         Dim ResponseStream As System.IO.Stream = _
                                objResponse.GetResponseStream() 
         ' Create the XmlDocument object from the 
         ' XML response stream. 
         Dim ResponseXmlDoc As New System.Xml.XmlDocument 
         ResponseXmlDoc.Load(ResponseStream) 
         ' Clean up. ResponseStream.Close() 
         objResponse.Close() 
         Return ResponseXmlDoc 
     Catch ex As Exception 
         ' Catch any exceptions. Any error codes from the method 
         ' requests on the server will be caught here, also. 
         AddInfo("& ex.ToString &"", 2) 
     End Try 
     Return Nothing 
 End Function

Finally, all the results are brought together in a DataTable object, and presented in a schedule with the free ScheduleGeneral custom control. The control will do all the work, we just bind it to the DataTable.

Points of interest

The project is an example of how to retrieve a list of Outlook calendar events from an exchange server with WebDAV.

History

This is the first version 1.0.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Jos Branders
Web Developer
Belgium Belgium
No Biography provided

You may also be interested in...

Comments and Discussions

 
QuestionCould not load file or assembly 'schedule' Pin
savitabhargav6-Dec-11 5:35
membersavitabhargav6-Dec-11 5:35 
GeneralSystem.Net.WebException Pin
donykas18-May-11 3:33
memberdonykas18-May-11 3:33 
Questionerror: System.NullReferenceException Pin
blauwvoet19-Oct-10 8:13
memberblauwvoet19-Oct-10 8:13 
GeneralMy vote of 5 Pin
thatraja6-Oct-10 1:37
memberthatraja6-Oct-10 1:37 
GeneralExchange 2007 / 2010 Pin
bingbongdong27-Jun-10 10:27
memberbingbongdong27-Jun-10 10:27 
GeneralRe: Exchange 2007 / 2010 Pin
Vamsi Praveen K14-Jul-11 0:49
memberVamsi Praveen K14-Jul-11 0:49 
GeneralWinform calender schedule control Pin
T G Shiva12-Nov-09 2:00
memberT G Shiva12-Nov-09 2:00 
GeneralRe: Winform calender schedule control Pin
darshana36913-Mar-10 0:15
memberdarshana36913-Mar-10 0:15 
QuestionOutlook Team Calendar Pin
inspirekarthick19-Oct-09 20:34
memberinspirekarthick19-Oct-09 20:34 
Hi everybody,

I am developing my senior project using ASP.NET.

This project has basically a calendar subsystem to be used by the users of the system which will be designed (the calendar) as .aspx code.

My concern is as follows:
Since most of us are using the Microsoft Outlook Calendar to organize their tasks and appointments, is there a way or a possible way (code fragments possibly) to link the data on the Outlook which includes the appointment date, time and description to my subsystem.
So, each slot in the outlook calendar will match a calendar cell in my project.

In other words, my calendar will be almost an identical copy of the outlook calendar content.

Looking forward for your replies.
Thanks in advance.
GeneralWill not show meetings ending at 5pm or after Pin
sweeetiepie21-Jul-09 13:28
membersweeetiepie21-Jul-09 13:28 
GeneralRe: Will not show meetings ending at 5pm or after Pin
bsinni26-Jul-09 13:29
memberbsinni26-Jul-09 13:29 
GeneralOnly able to query one user Pin
hartmann12315-Jun-09 8:53
memberhartmann12315-Jun-09 8:53 
GeneralRe: Only able to query one user Pin
hartmann12315-Jun-09 23:50
memberhartmann12315-Jun-09 23:50 
QuestionHow do you display hyperlink in description? Pin
Kathy_OC13-May-09 3:55
memberKathy_OC13-May-09 3:55 
QuestionStart/End time Pin
civanescu30-Mar-09 4:16
membercivanescu30-Mar-09 4:16 
AnswerRe: Start/End time Pin
KHaymo21-Apr-09 4:06
memberKHaymo21-Apr-09 4:06 
QuestionGetting error Pin
Member 279269422-Jan-09 0:06
memberMember 279269422-Jan-09 0:06 
AnswerRe: Getting error Pin
aggerholm7-May-09 2:29
memberaggerholm7-May-09 2:29 
QuestionRe: Getting error Pin
ramsmca25-May-09 20:02
memberramsmca25-May-09 20:02 
AnswerRe: Getting error Pin
donykas18-May-11 23:53
memberdonykas18-May-11 23:53 
QuestionLe serveur distant a retourné une erreur : (500) Erreur interne du serveur. Pin
telone26-Nov-08 5:11
membertelone26-Nov-08 5:11 
GeneralError message "(403) Forbidden" Pin
bvaar6-Nov-08 3:10
memberbvaar6-Nov-08 3:10 
QuestionAbout the 403 Forbidden message Pin
Aaog17-Sep-08 8:28
memberAaog17-Sep-08 8:28 
AnswerRe: About the 403 Forbidden message Pin
Jos Branders20-Sep-08 3:57
memberJos Branders20-Sep-08 3:57 
GeneralRe: About the 403 Forbidden message Pin
Aaog24-Sep-08 4:02
memberAaog24-Sep-08 4:02 
GeneralRe: About the 403 Forbidden message Pin
brannpos11-Jul-12 1:51
memberbrannpos11-Jul-12 1:51 
QuestionThe remote server returned an error: (404) Not Found. Pin
shalom47476-Jun-08 5:24
membershalom47476-Jun-08 5:24 
AnswerRe: The remote server returned an error: (404) Not Found. [modified] Pin
nilsreuvers1-Jul-08 1:09
membernilsreuvers1-Jul-08 1:09 
GeneralPicture of what is possible with this gem Pin
asphalt_it20-May-08 11:46
memberasphalt_it20-May-08 11:46 
GeneralRe: Picture of what is possible with this gem Pin
juno-223-May-08 4:39
memberjuno-223-May-08 4:39 
GeneralEnhance with tooltips Pin
asphalt_it20-May-08 8:48
memberasphalt_it20-May-08 8:48 
GeneralAll Day Events Pin
asphalt_it13-May-08 7:51
memberasphalt_it13-May-08 7:51 
GeneralRe: All Day Events Pin
Fred Simpson20-May-08 20:58
memberFred Simpson20-May-08 20:58 
QuestionHave you seen this? Pin
Lars Mørch6-May-08 20:58
memberLars Mørch6-May-08 20:58 
GeneralVirtual Directory Pin
asphalt_it30-Apr-08 4:58
memberasphalt_it30-Apr-08 4:58 
QuestionStyling of calendar? Pin
juno-224-Apr-08 21:53
memberjuno-224-Apr-08 21:53 
GeneralAll Day Event Pin
Member 412979416-Apr-08 4:33
memberMember 412979416-Apr-08 4:33 
GeneralRe: All Day Event [modified] Pin
nilsreuvers4-Jul-08 1:45
membernilsreuvers4-Jul-08 1:45 
QuestionHow to create an account that is able to read all users calendar? Pin
chinh8012-Mar-08 19:37
memberchinh8012-Mar-08 19:37 
AnswerRe: How to create an account that is able to read all users calendar? Pin
Jos Branders22-Mar-08 4:29
memberJos Branders22-Mar-08 4:29 
AnswerRe: How to create an account that is able to read all users calendar? Pin
nilsreuvers4-Jul-08 1:21
membernilsreuvers4-Jul-08 1:21 
QuestionHiding the Private meetings Subject Line Pin
shoemakerbrian8-Oct-07 9:47
membershoemakerbrian8-Oct-07 9:47 
AnswerRe: Hiding the Private meetings Subject Line Pin
mr.Gargol16-Nov-07 5:04
membermr.Gargol16-Nov-07 5:04 
GeneralRe: Hiding the Private meetings Subject Line Pin
Fred Simpson22-May-08 2:25
memberFred Simpson22-May-08 2:25 
GeneralRe: Hiding the Private meetings Subject Line Pin
mr.Gargol22-May-08 2:51
membermr.Gargol22-May-08 2:51 
GeneralRe: Hiding the Private meetings Subject Line Pin
Fred Simpson22-May-08 3:34
memberFred Simpson22-May-08 3:34 
GeneralRe: Hiding the Private meetings Subject Line Pin
mr.Gargol22-May-08 3:52
membermr.Gargol22-May-08 3:52 
GeneralRe: Hiding the Private meetings Subject Line Pin
Fred Simpson22-May-08 20:46
memberFred Simpson22-May-08 20:46 
GeneralRe: Hiding the Private meetings Subject Line Pin
mr.Gargol22-May-08 23:47
membermr.Gargol22-May-08 23:47 
Generalerror: (403) Forbidden Pin
dpolvere4-Jul-07 6:53
memberdpolvere4-Jul-07 6:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150901.1 | Last Updated 3 Sep 2005
Article Copyright 2005 by Jos Branders
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid