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入门指南: