how to read calender from exchange server RRS feed

  • General discussion

  • If now i need to read out the calender or appointment from exchange server, how shall i do.

    my project is a application that when you click the button, the appointment will pop out.

    PS: if i am not wrong, the exchange server has its own database to store the mail (who use the outlook to create).so actually my project's function is similar with outlook, now i want to read calender, can you help me?
    this is the function what i found, is it useful
    Private Function GetCalendar() As String 
            ' Variables  
            Dim Request As System.Net.HttpWebRequest  
            Dim Response As System.Net.HttpWebResponse  
            Dim MyCredentialCache As System.Net.CredentialCache  
            Dim strPassword As String 
            Dim strUserName As String 
            Dim strContactListURI As String 
            Dim strCalendarURI As String 
            Dim strQuery As String 
            Dim bytes() As Byte 
            Dim RequestStream As System.IO.Stream  
            Dim ResponseStream As System.IO.Stream  
            Dim ResponseXmlDoc As System.Xml.XmlDocument  
            Dim HrefNodes As System.Xml.XmlNodeList  
            Dim SizeNodes As System.Xml.XmlNodeList  
            Dim SubjectNodeList As System.Xml.XmlNodeList  
            Dim LocationNodeList As System.Xml.XmlNodeList  
            Dim StartTimeNodeList As System.Xml.XmlNodeList  
            Dim EndTimeNodeList As System.Xml.XmlNodeList  
            Dim BusyStatusNodeList As System.Xml.XmlNodeList  
            Dim InstanceTypeNodeList As System.Xml.XmlNodeList  
            Dim strBS As New System.Text.StringBuilder  
                ' Initialize variables.  
                strUserName = "DOMAIN\USERNAME" 
                strPassword = "PW" 
                strCalendarURI = "http://mail.domain.com/public/CalendarName/" 
                ' Build the SQL query.  
                strQuery = "<?xml version=""1.0""?>" & _  
                           "<g:searchrequest xmlns:g=""DAV:"">" & _  
                           "<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 """ & strCalendarURI & """') " & _  
                           "WHERE NOT ""urn:schemas:calendar:instancetype"" = 1 " & _  
                           "AND ""DAV:contentclass"" = 'urn:content-classes:appointment' " & _  
                           "AND ""urn:schemas:calendar:dtstart"" > '2003/06/01 00:00:00' " & _  
                           "ORDER BY ""urn:schemas:calendar:dtstart"" ASC" & _  
                ' Create a new CredentialCache object and fill it with the network  
                ' credentials required to access the server.  
                MyCredentialCache = New System.Net.CredentialCache  
                MyCredentialCache.Add(New System.Uri(strContactListURI), _  
                    "BASIC", _  
                    New System.Net.NetworkCredential(strUserName, strPassword) _  
                ' Create the PUT HttpWebRequest object.  
                Request = CType(System.Net.WebRequest.Create(strContactListURI),  _  
                ' Add the network credentials to the request.  
                Request.Credentials = MyCredentialCache  
                ' Specify the SEARCH method.  
                Request.Method = "SEARCH" 
                ' Encode the body using UTF-8.  
                bytes = System.Text.Encoding.UTF8.GetBytes(strQuery)  
                ' Set the content header length.  This must be  
                ' done before writing data to the request stream.  
                Request.ContentLength = bytes.Length  
                ' Get a reference to the request stream.  
                RequestStream = Request.GetRequestStream()  
                ' Write the message body to the request stream.  
                RequestStream.Write(bytes, 0, bytes.Length)  
                ' Close the Stream object to release the connection  
                ' for further use.  
                ' Set the Content Type header.  
                Request.ContentType = "text/xml" 
                ' Set the Translate header.  
                ' Send the SEARCH method request and get the  
                ' response from the server.  
                Response = CType(Request.GetResponse(), System.Net.HttpWebResponse)  
                ' Get the XML response stream.  
                ResponseStream = Response.GetResponseStream()  
                ' Create the XmlDocument object from the XML response stream.  
                ResponseXmlDoc = New System.Xml.XmlDocument  
                ' Build a list of the DAV:href XML nodes, corresponding to the folders  
                ' in the mailbox.  The DAV: namespace is typically assgigned the a:  
                ' prefix in the XML response body.  
                HrefNodes = ResponseXmlDoc.GetElementsByTagName("a:href")  
                SubjectNodeList = ResponseXmlDoc.GetElementsByTagName("d:subject")  
                LocationNodeList = ResponseXmlDoc.GetElementsByTagName("d:location")  
                StartTimeNodeList = ResponseXmlDoc.GetElementsByTagName("d:dtstart")  
                EndTimeNodeList = ResponseXmlDoc.GetElementsByTagName("d:dtend")  
                BusyStatusNodeList = ResponseXmlDoc.GetElementsByTagName("d:busystatus")  
                InstanceTypeNodeList = ResponseXmlDoc.GetElementsByTagName("d:instancetype")  
                ' Loop through the returned items (if any).  
                If SubjectNodeList.Count > 0 Then 
                    strBS.Append("Calendar List items..." & vbCrLf)  
                    Dim i As Integer 
                    For i = 0 To SubjectNodeList.Count - 1  
                        strBS.Append("subject:       " + SubjectNodeList(i).InnerText & vbCrLf)  
                        strBS.Append("location:      " + LocationNodeList(i).InnerText & vbCrLf)  
                        strBS.Append("dtstart:    " + StartTimeNodeList(i).InnerText & vbCrLf)  
                        strBS.Append("dtend:      " + EndTimeNodeList(i).InnerText & vbCrLf)  
                        strBS.Append("busystatus:   " + BusyStatusNodeList(i).InnerText & vbCrLf)  
                        strBS.Append("instancetype:   " + InstanceTypeNodeList(i).InnerText & vbCrLf)  
                    strBS.Append("No calendar items found ...")  
                End If 
                ' Clean up.  
            Catch ex As Exception  
                ' Catch any exceptions. Any error codes from the  
                ' SEARCH method requests on the server will be caught  
                ' here, also.  
            End Try 
            Return strBS.ToString()  
        End Function 

    Wednesday, June 11, 2008 6:27 AM

All replies