使用 Exchange Web Service (EWS) 更新會議的做法
請參考下列的程式碼粗體字的時間指定. 若沒有指定, 時間會變成 UTC .
Central Standard Time 可以指定為 Taipei Standard Time 即為台北的時區.
static void UpdateAppointmentTimeZone(ExchangeService service, ItemId apptId, bool shiftAppointment)
{
PropertySet includeTimeZones = new PropertySet(AppointmentSchema.Subject,
AppointmentSchema.Start,
AppointmentSchema.ReminderDueBy,
AppointmentSchema.End,
AppointmentSchema.StartTimeZone,
AppointmentSchema.EndTimeZone);
Appointment apptToUpdate;
// Load the existing appointment.
// This will result in a call to EWS.
try
{
apptToUpdate = Appointment.Bind(service, apptId, includeTimeZones);
}
catch (Exception ex)
{
Console.WriteLine("Error retrieving existing appointment: {0}", ex.Message);
return;
}
Console.WriteLine("Before update:");
// Output the current start, reminder, end, and time zones.
Console.WriteLine(" Start: {0}", apptToUpdate.Start);
Console.WriteLine(" Start time zone: {0}", apptToUpdate.StartTimeZone.DisplayName);
Console.WriteLine(" Reminder: {0}", apptToUpdate.ReminderDueBy);
Console.WriteLine(" End: {0}", apptToUpdate.End);
Console.WriteLine(" End time zone: {0}", apptToUpdate.EndTimeZone.DisplayName);
// Retrieve the Central time zone.
TimeZoneInfo centralTZ = TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time");
// Update the time zones on the appointment.
apptToUpdate.StartTimeZone = centralTZ;
apptToUpdate.EndTimeZone = centralTZ;
if (!shiftAppointment)
{
// Set the start and end times explicitly so that the appointment
// will start and end at the same UTC time.
// Convert the times to then Central time zone. This
// will keep them at the same time in UTC.
// For example, 1:00 PM Eastern becomes 12:00 PM Central.
DateTime newStartTime = TimeZoneInfo.ConvertTime(
apptToUpdate.Start, centralTZ);
DateTime newEndTime = TimeZoneInfo.ConvertTime(
apptToUpdate.End, centralTZ);
apptToUpdate.Start = newStartTime;
apptToUpdate.End = newEndTime;
}
try
{
// Save the changes. This will result in a call to EWS.
apptToUpdate.Update(ConflictResolutionMode.AlwaysOverwrite,
SendInvitationsOrCancellationsMode.SendToNone);
}
catch (Exception ex)
{
Console.WriteLine("Error updating appointment: {0}", ex.Message);
return;
}
// Now rebind to the appointment to get the new values.
Appointment apptAfterUpdate;
try
{
// This will result in a call to EWS.
apptAfterUpdate = Appointment.Bind(service, apptId, includeTimeZones);
}
catch (Exception ex)
{
Console.WriteLine("Error retrieving existing appointment: {0}", ex.Message);
return;
}
Console.WriteLine("After update:");
// Output the current start, reminder, end, and time zones.
Console.WriteLine(" Start: {0}", apptAfterUpdate.Start);
Console.WriteLine(" Start time zone: {0}", apptAfterUpdate.StartTimeZone.DisplayName);
Console.WriteLine(" Reminder: {0}", apptAfterUpdate.ReminderDueBy);
Console.WriteLine(" End: {0}", apptAfterUpdate.End);
Console.WriteLine(" End time zone: {0}", apptAfterUpdate.EndTimeZone.DisplayName);
}
For more information: https://msdn.microsoft.com/en-us/library/office/dn789030(v=exchg.150).aspx
HTH. Jacky