4

我正在使用 EWS 1.2 发送约会。在创建新约会时,时区在通知邮件上正确显示,但在更新同一约会时,时区重置为 UTC。

谁能帮我解决这个问题?

这是复制问题的示例代码:

ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP1, TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time"));
service.Credentials = new WebCredentials("ews_calendar", PASSWORD, "acme");
service.Url = new Uri("https://acme.com/EWS/Exchange.asmx");

Appointment newAppointment = new Appointment(service);
newAppointment.Subject = "Test Subject";
newAppointment.Body = "Test Body";
newAppointment.Start = new DateTime(2012, 03, 27, 17, 00, 0);
newAppointment.End = newAppointment.Start.AddMinutes(30);
newAppointment.RequiredAttendees.Add("tin.tin@acme.com");

//Attendees get notification mail for this appointment using (UTC-05:00) Eastern Time (US & Canada) timezone
//Here is the notification content received by attendees:
//When: Tuesday, March 27, 2012 5:00 PM-5:30 PM. (UTC-05:00) Eastern Time (US & Canada)
newAppointment.Save(SendInvitationsMode.SendToAllAndSaveCopy);

// Pull existing appointment
string itemId = newAppointment.Id.ToString();

Appointment existingAppointment = Appointment.Bind(service, new ItemId(itemId));

//Attendees get notification mail for this appointment using UTC timezone
//Here is the notification content received by attendees:
//When: Tuesday, March 27, 2012 11:00 PM-11:30 PM. UTC
existingAppointment.Update(ConflictResolutionMode.AlwaysOverwrite, SendInvitationsOrCancellationsMode.SendToAllAndSaveCopy);
4

2 回答 2

1

You'll want to set AppointmentSchema.StartTimeZone and bind it as part of the properties object when you bind existingAppointment, as illustrated here:

// Get an existing calendar item, requesting the Id, Start, and 
//  StartTimeZone properties.
PropertySet props = new PropertySet(
      AppointmentSchema.Id, 
      AppointmentSchema.Start, 
      AppointmentSchema.StartTimeZone);
Appointment appt = Appointment.Bind(service, new ItemId("AQMkA="), props);

It seems the default bound time zone is UTC.

于 2012-04-01T23:15:20.680 回答
1

尝试使用Bind()允许显式指定要加载的属性的其他重载。基本上TimeZone在第三个参数中指定所有特定属性定义Bind(),关于 MSDN 的论文To change time zone for an interview without changes the start time

使用其唯一标识符绑定到现有约会。以下代码显示如何绑定到现有约会,使用名为 service 的 ExchangeService 对象为其提供连接配置信息,并请求特定的属性子集,包括 DateTime 属性和时区属性。ItemId 已被缩短以保持可读性。出于本示例的目的,假设服务对象的范围为太平洋标准时间 (PST) 时区。

var appt = Appointment.Bind(
            service, 
            new ItemId(itemId), 
            new PropertySet(
                  BasePropertySet.IdOnly, 
                  AppointmentSchema.Start, 
                  AppointmentSchema.ReminderDueBy, 
                  AppointmentSchema.End, 
                  AppointmentSchema.StartTimeZone, 
                  AppointmentSchema.EndTimeZone, 
                  AppointmentSchema.TimeZone)); 

appt.StartTimeZone = TimeZoneInfo.FindSystemTimeZoneById("Coordinated Universal Time");
appt.EndTimeZone = TimeZoneInfo.FindSystemTimeZoneById("Coordinated Universal Time");

appt.Update(
        ConflictResolutionMode.AlwaysOverwrite, 
        SendInvitationsOrCancellationsMode.SendToAllAndSaveCopy);

appt.Load(new PropertySet(
                   BasePropertySet.IdOnly, 
                   AppointmentSchema.Start,              
                   AppointmentSchema.ReminderDueBy, 
                   AppointmentSchema.End, 
                   AppointmentSchema.StartTimeZone, 
                   AppointmentSchema.EndTimeZone, 
                   AppointmentSchema.TimeZone));

     您还可以在下面找到有用的 MSDN how-tos:

于 2012-04-06T11:20:31.677 回答