更新约会时TimeZone更改为UTC

时间:2012-03-28 14:54:10

标签: sharepoint-2010 exchangewebservices exchange-server-2010

我正在使用EWS 1.2发送约会。在创建新的约会时,TimeZone正在显示通知邮件,但在更新相同的约会时,它会将TimeZone重置为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);

2 个答案:

答案 0 :(得分:1)

当您AppointmentSchema.StartTimeZone绑定existingAppointment时,您需要设置// 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); 并将其绑定为属性对象的一部分:

{{1}}

似乎默认的绑定时区是UTC。

答案 1 :(得分:1)

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

  

使用其唯一标识符绑定到现有约会。该   以下代码显示了如何绑定到现有约会,提供   它使用连接配置信息   ExchangeService对象名为service,并请求特定的子集   属性,包括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方法: