Obtaining appointment.body.text from findItemResults RRS feed

  • Question

  • My current code:

    1. Establishes connection
    2. Searches for appointment(s) within the specified day (hardcoded currently)
    3. Creates an XML with the data returned

    The XML created has a "minor" problem though. It is html not text so when it is retrieved instead of getting


    I get

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta name="Generator" content="Microsoft Exchange Server">
    <!-- converted from rtf -->
    <style><!-- .EmailQuote { margin-left: 1pt; padding-left: 4pt; border-left: #800000 2px solid; } --></style>
    <font face="Times New Roman" size="3"><span style="font-size:12pt;"><a name="BM_BEGIN"></a>
    <div> </div>
    <div> </div>

    Code is below. Where am I going wrong?

                ' Network Credentials
                Dim UserCal As String = "Bert"
                Dim Password As String = "&Earnie"
                Dim strDomain As String = "SesameStreet"
                Dim strRtDomain As String = "HBC"
                ' Connection
                Dim service As New ExchangeService(ExchangeVersion.Exchange2010)
                ServicePointManager.ServerCertificateValidationCallback = New RemoteCertificateValidationCallback(AddressOf ValidateCertificate)
                service.Url = New Uri("https://" & strRtDomain & "/EWS/exchange.asmx")
                service.Credentials = New NetworkCredential(UserCal, Password, strDomain)
                ' Debugging
                service.TraceListener = TC
                service.TraceFlags = TraceFlags.EwsResponse
                service.TraceEnabled = True
                ' Info about?
                Dim appointment As New Microsoft.Exchange.WebServices.Data.Appointment(service)
                Dim dtSlot As New DateTime(2012, 3, 21, 0, 0, 0, DateTimeKind.Local)
                Dim dtEndDate As DateTime
                dtEndDate = dtSlot.AddDays(1)
                Dim calView As New CalendarView(dtSlot, dtEndDate, 30)
                ' Search request
                Dim findRes As FindItemsResults(Of Microsoft.Exchange.WebServices.Data.Appointment) = service.FindAppointments(WellKnownFolderName.Calendar, calView)
                ' XML creation
                Dim strPath As String = System.AppDomain.CurrentDomain.BaseDirectory
                Dim xmlDoc As New XmlDocument
                Dim dec As XmlDeclaration = xmlDoc.CreateXmlDeclaration("1.0", Nothing, Nothing)
                Dim docroot As XmlElement = xmlDoc.CreateElement("t:Items")
                For Each Appt As Microsoft.Exchange.WebServices.Data.Appointment In findRes
                    Dim calitem As XmlElement = xmlDoc.CreateElement("CalendarItem")
    				Dim subject As XmlElement = xmlDoc.CreateElement("e:subject")
                    subject.InnerText = Appt.Subject.ToString
                    Dim location As XmlElement = xmlDoc.CreateElement("d:location")
                    location.InnerText = Appt.Location.ToString
                    Dim desc As XmlElement = xmlDoc.CreateElement("e:htmldescription")
                    Dim body As New PropertySet(BasePropertySet.FirstClassProperties)
                    Appt.Body.BodyType = BodyType.HTML
                    desc.InnerText = Appt.Body.Text
                ' Save XML
                xmlDoc.Save(strPath + \\lookup.xml)
    Wednesday, February 1, 2012 5:26 PM

All replies

  • > Obtaining appointment.body.text from findItemResults

    To firstly answer this one the body (and any other large streaming property) wont be returned in the FindItems Results you will only get the first 512 bytes of these type of properties see the Remarks section of

    So if you want to retrieve the body you need to do a GetItem request (or a load in the Managed API) the most effiencent way of doing this for multiple calendar items is explained in

    One important point when retrieve the body of any Item the default body that EWS will return is HTML (doesn't mater if you only create the item with a Text body the Store will automatically convert this to HTML and return that to you). So its important if you do want the body as Text in you request that you specify that.

    With your code

                    Dim body As New PropertySet(BasePropertySet.FirstClassProperties)


    With a GetItem if your specifying the BasePropertySet.FirstClassProperties the body will be included so this isn't needed

    If you want the server to return a Text Body you need

    body.RequestedBodyType.Value = BodyType.Text

    with Appt.Body.Text this will be HTML or Text based on what is set in the PropertySet your loading


    Thursday, February 2, 2012 5:52 AM