Change TimeZone to UTC when updating Destination

I use EWS 1.2 to send appointments. When creating new Destinations, TimeZone correctly displays notification mail, but when updating the same destination, TimeZone reset indicates UTC.

Can someone help me solve this problem?

Here is sample code to replicate the problem:

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); 
+4
source share
2 answers

You want to set AppointmentSchema.StartTimeZone and bind it as part of the properties object when binding the existingAppointment , as shown 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); 

The default timezone seems to be UTC.

+1
source

Try using another Bind() overload, which allows you to explicitly specify which properties to load. Basically specify the entire TimeZone definition of a specific property in the third parameter of Bind() , in relation to MSDN paper. To change the time zone for a meeting without changing the start time :

Bind to an existing destination using its unique identifier. The following code shows how to attach to an existing meeting, provide information about the connection configuration using an ExchangeService object named service, and requests a specific subset of the property, including the DateTime properties and the time zone of the property. ItemId has been shortened to maintain readability. For the purposes of this example, suppose that the service object has a scope by Pacific Standard Time (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)); 

Also below you can find helpful MSDN instructions:

+1
source

Source: https://habr.com/ru/post/1403924/


All Articles