EWS API を使用して予定をユーザーの交換カレンダーにエクスポートしています。正常に動作していましたが、予定で、テーブルの配置などでhtmlが適切にフォーマットされていないことに気付きました。そのため、予定の本文の種類のプロパティを HTML に設定しようとしましたが、プロパティを設定した行で「値を読み取る前に、このプロパティを読み込むか割り当てる必要があります」という ServiceObjectPropertyException が発生しました。
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);
}