cpiasecki
cpiasecki

Reputation: 47

ServiceObjectPropertyException on an EWS Appointment

i'm using the EWS API to export an appointment to a user's exchange calender. It was working fine but I noticed in the appointment the html was not formatted properly with the table aligning and such. So I tried setting the appointment body type property to HTML but got the ServiceObjectPropertyException saying "You must load or assign this property before you can read its value" on that line where I set the property.

                User SelectedUser = UserController.GetExchangeCredentials(UserID);

                //If they have their exchange credentials setup then create the appointment in their exchange calender
                if (SelectedUser.ExchangeUsername != String.Empty)
                {
                    Client ClientInfo = ClientController.GetContactInfoForCalenderAppointment(int.Parse(btn_SubmitNextContactDate.CommandArgument.ToString()), int.Parse(ddl_Contact.SelectedValue));

                    //Setup the exchange service with the user credentials of that receiving the appointment
                    ExchangeService Service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
                    Service.UseDefaultCredentials = false;
                    Service.Credentials = new WebCredentials(SelectedUser.ExchangeUsername, SelectedUser.ExchangePassword, SelectedUser.ServerDomain);
                    Service.AutodiscoverUrl(SelectedUser.Email);

                    //Create the appointment
                    Microsoft.Exchange.WebServices.Data.Appointment Appointment = new Microsoft.Exchange.WebServices.Data.Appointment(Service);
                    Appointment.Body.BodyType = BodyType.HTML;
                    Appointment.Subject = "Next Contact Date for " + OperatingName.Text;                        
                    Appointment.Body = "<table><tr><td><b>Client Name:</b></td><td>" + ClientName.Text + "</td></tr>";
                    Appointment.Body += "<tr><td><b>Operating Name:</b></td><td>" + OperatingName.Text + "</td></tr>";
                    Appointment.Body += "<tr><td><b>Service:</b></td><td>" + ddl_ServiceType.SelectedItem.Text + "</td></tr>";
                    Appointment.Body += "<tr><td><b>Contact Method:</b></td><td>" + ddl_ContactMethod.SelectedItem.Text + "</td></tr>";
                    Appointment.Body += "<tr><td><b>Contact Name:</b></td><td>" + ddl_Contact.SelectedItem.Text + "</td></tr>";
                    Appointment.Body += "<tr><td><b>Contact Phone:</b></td><td>" + ClientInfo.Contacts[0].Phone + "</td></tr>";
                    Appointment.Body += "<tr><td><b>Contact Email:</b></td><td>" + ClientInfo.Contacts[0].Email + "</td></tr>";
                    Appointment.Body += "<tr><td><b>Client Address 1:</b></td><td>" + ClientInfo.Address1 + "</td></tr>";
                    Appointment.Body += "<tr><td><b>Note:</b></td><td>" + txt_NextContactDateNote.Content + "</td></tr></table>";
                    Appointment.Start = DateTime.Parse(txt_NextContactDate.Text);
                    Appointment.End = DateTime.Parse(txt_NextContactDate.Text);
                    Appointment.Save(SendInvitationsMode.SendToNone);
                }                

Upvotes: 1

Views: 1453

Answers (1)

SliverNinja - MSFT
SliverNinja - MSFT

Reputation: 31651

This works fine in Exchange 2010 SP1...I don't have Exchange 2007 SP1 to test it out.

Appointment appt = new Appointment(service)
{
    Subject = "Next Contact Date",
    Body = new MessageBody()
    {
        BodyType = BodyType.HTML,
        Text = "here is some body content. <b>this is bold</b>" +
              "<table><tr><td><b>Client name: </b></td><td>George</td></tr></table>",
    },
    Start = DateTime.Now.AddDays(1),
    End = DateTime.Now.AddDays(1).AddHours(.5),
};
appt.Save();

Upvotes: 1

Related Questions