Click here to Skip to main content
15,881,089 members
Articles / Web Development / ASP.NET
Article

Outlook Team Calendar

Rate me:
Please Sign up or sign in to vote.
3.41/5 (16 votes)
3 Sep 20052 min read 447.8K   8K   125   127
Show your team's calendars side by side in a single web page.

Image 1

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.

XML
<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:

VB
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>, 2)
    End If 
    Return Nothing 
End Function

The result will be an XmlDocument object.

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

VB
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


Written By
Web Developer
Belgium Belgium
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralRe: error: (403) Forbidden Pin
BarryH24-Mar-08 18:45
BarryH24-Mar-08 18:45 
GeneralRe: error: (403) Forbidden Pin
dpolvere25-Mar-08 4:11
dpolvere25-Mar-08 4:11 
GeneralRe: error: (403) Forbidden Pin
brannpos11-Jul-12 1:49
brannpos11-Jul-12 1:49 
GeneralSolution to the 400 Error and More Pin
tstone@hanalani.org22-Jun-07 15:49
tstone@hanalani.org22-Jun-07 15:49 
QuestionQuerying using Webdav... Pin
Elfman_NE18-Jun-07 8:41
Elfman_NE18-Jun-07 8:41 
General(401) Unauthorized Pin
chetstriker28-May-07 17:39
chetstriker28-May-07 17:39 
GeneralSee also my control (DayPilot) Pin
Dan Letecky10-Apr-07 20:39
Dan Letecky10-Apr-07 20:39 
QuestionError 404 when accessing this server Pin
sFernandeZZ20-Feb-07 5:14
sFernandeZZ20-Feb-07 5:14 
GeneralASP Classic example Pin
Member 37888386-Feb-07 6:43
Member 37888386-Feb-07 6:43 
General440 Login Timeout Pin
lamlamz22-Jan-07 16:33
lamlamz22-Jan-07 16:33 
AnswerRe: 440 Login Timeout Pin
sgibbs19-Aug-07 6:14
sgibbs19-Aug-07 6:14 
GeneralRe: 440 Login Timeout Pin
paulclift29-Oct-09 5:55
paulclift29-Oct-09 5:55 
QuestionServer Application Unavailable Pin
gagop19-Jan-07 8:28
gagop19-Jan-07 8:28 
GeneralError 401 (Bad Request) Pin
browna13-Dec-06 5:38
browna13-Dec-06 5:38 
AnswerRe: Error 401 (Bad Request) Pin
Magnus Jacobsen13-Dec-06 12:16
Magnus Jacobsen13-Dec-06 12:16 
GeneralRe: Error 401 (Bad Request) Pin
browna13-Dec-06 22:13
browna13-Dec-06 22:13 
GeneralRe: Error 401 (Bad Request) [modified] Pin
Chrono12314-Aug-07 23:03
Chrono12314-Aug-07 23:03 
QuestionShared cal's not displaying Pin
mondaygirl15-Nov-06 0:29
mondaygirl15-Nov-06 0:29 
AnswerRe: Shared cal's not displaying Pin
Magnus Jacobsen8-Dec-06 12:34
Magnus Jacobsen8-Dec-06 12:34 
AnswerRe: Shared cal's not displaying Pin
Magnus Jacobsen13-Dec-06 12:41
Magnus Jacobsen13-Dec-06 12:41 
GeneralRe: Shared cal's not displaying Pin
donykas18-May-11 23:40
donykas18-May-11 23:40 
GeneralC# Pin
Lawrence Staff (aka Lozza)20-Oct-06 3:03
Lawrence Staff (aka Lozza)20-Oct-06 3:03 
GeneralError 401.5 Pin
bentley3220-Jul-06 7:34
bentley3220-Jul-06 7:34 
GeneralWinform Pin
lemccain29-Jun-06 8:59
lemccain29-Jun-06 8:59 
GeneralAll it needs is SSL Pin
mcunn21-Jun-06 9:46
mcunn21-Jun-06 9:46 

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

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