EWS约会上的ServiceObjectPropertyException

时间:2012-08-17 16:52:04

标签: asp.net exchangewebservices

我正在使用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);
                }                

1 个答案:

答案 0 :(得分:1)

这在 Exchange 2010 SP1 中运行良好...我没有 Exchange 2007 SP1 来测试它。

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();