4

我正在使用EWS 1.2發送約會。在創建新約會時,TimeZone會在通知郵件上正確顯示,但在更新同一約會時,TimeZone會重置爲UTC。更新約會時區更改爲UTC

任何人都可以幫助我解決這個問題嗎?

下面是示例代碼複製的問題:當你綁定existingAppointment

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("[email protected]"); 

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

回答

1

你要設置AppointmentSchema.StartTimeZone並將其綁定的屬性的一部分對象,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); 

看起來默認的綁定時區是UTC。

+0

我按照你的建議設置了AppointmentSchema.StartTimeZone,但EWS仍然以UTC時區發送通知郵件。 – 2012-04-02 13:21:42

+0

@FirozAnsari瞭解。同樣,當你在上面的代碼中爲'newAppointment'綁定它時會發生什麼? [鏈接文章](http://msdn.microsoft.com/en-us/library/ee332363(v = exchg.140).aspx)似乎涵蓋了針對Exchange 2010 EWS中的這個確切問題和功能的許多情況。除非您可以收集有關服務器屬性的更多信息,否則我認爲在定義明確的時區時與其聯繫是最合適的操作方式。 – MrGomez 2012-04-02 18:52:00

+0

謝謝MrGomez。使用newAppointment,通知時區是正確的。我唯一的問題是更新現有的約會。我看了這篇文章,這篇文章解釋瞭如何將開始日期和結束日期轉換爲特定的時區。我不知道如何在調用existingAppointment.Update時轉換日期。再次感謝您的幫助。 – 2012-04-03 13:20:33

1

嘗試使用Bind()的其他超載,允許顯式指定要加載的屬性。基本上所有指定特定TimeZone屬性定義的第三個參數的Bind(),關於MSDN的紙To change the time zone for an appointment without changing 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入門指南: