TimeZone change to UTC while updating the Appointment

别说谁变了你拦得住时间么 提交于 2019-12-01 20:11:21

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.

Try out using an other overload of Bind() which allows explicitly specifying which properties to load. Basically specify all TimeZone specific property definition in third parameter of Bind(), regarding MSDN's paper To change the time zone for an appointment without changing the start time:

Bind to the existing appointment by using its unique identifier. The following code shows how to bind to an existing appointment, provide it with connection configuration information by using an ExchangeService object named service, and request a specific subset of properties, including the DateTime properties and the time zone properties. The ItemId has been shortened to preserve readability. For the purpose of this example, assume that the service object is scoped to the Pacific Standard Time (PST) time zone.

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

     Also below you can find useful MSDN how-tos:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!