none
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

    ABCDEFGHIJKLMNOPQRSTUVWXYZ

    I get

    <html>
    <head>
    <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>
    </head>
    <body>
    <font face="Times New Roman" size="3"><span style="font-size:12pt;"><a name="BM_BEGIN"></a>
    <div> </div>
    <div> </div>
    <div>ABCDEFGHIJKLMNOPQRSTUVWXYZ</div>
    </span></font>
    </body>
    </html>

    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)
                xmlDoc.AppendChild(dec)
                Dim docroot As XmlElement = xmlDoc.CreateElement("t:Items")
                xmlDoc.AppendChild(docroot)
    			
                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)
                    body.Add(ItemSchema.Body)
                    Appt.Load(body)
                    Appt.Body.BodyType = BodyType.HTML
                    desc.InnerText = Appt.Body.Text
    				
                    docroot.AppendChild(calitem)
                    xmlDoc.DocumentElement.LastChild.AppendChild(subject)
                    xmlDoc.DocumentElement.LastChild.AppendChild(location)
                    xmlDoc.DocumentElement.LastChild.AppendChild(desc)
                Next
    			
                ' 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 http://msdn.microsoft.com/en-us/library/aa566107(v=exchg.140).aspx.

    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  http://social.technet.microsoft.com/Forums/en-US/exchangesvrdevelopment/thread/ce1e0527-e2db-490d-817e-83f586fb1b44

    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)

    Okay
                    body.Add(ItemSchema.Body)

    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
    Appt.Load(body)

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


    Cheers
    Glen

    Thursday, February 2, 2012 5:52 AM