Search code examples
c#outlookcalendarexchangewebservices

How to Set Timezone for Outlook Appointment.When if created via EWS API


We are using Exchange Web Services API to create the Appointment. We set the timezone to local timezone during creation. When recipients view the invite, it is the right time at his local timezone, the only thing is that Exchange adds "When" and "Where" at the beginning of appointment body like this:

Appointment

The timezone for When is always in UTC timezone no matter what end user's timezone is. This causes some confusion for end users of our customers. From EWS API Document for Appointment.When property, there is only Get method, not Set method. In one test, we tried to set the Preferred culture to de-de culture as document is suggested and "When" is still displayed in UTC time. Setting Preferred Culture

Somehow I could not find any related information on this over the internet. Could anyone shed some lights here about how to have "When" to be displayed in certain timezone?


Solution

  • What your looking at is referred to as downlevel text in the Message body, the issue generally occurs during an update of the appointment which you seem to be doing as the last line of the image you posted. The problem is because the timezone doesn't get sent as part of the update request the server will set the downlevel text to utc. One work around for this is you can add the TimeZoneContext header manually using

    OnSerializeCustomSoapHeaders event eg

            service.OnSerializeCustomSoapHeaders += service_OnSerializeCustomSoapHeaders;
            appointment.Update(ConflictResolutionMode.AlwaysOverwrite, SendInvitationsOrCancellationsMode.SendToAllAndSaveCopy);
            service.OnSerializeCustomSoapHeaders -= service_OnSerializeCustomSoapHeaders;
    
        static void service_OnSerializeCustomSoapHeaders(XmlWriter writer)
        {
            writer.WriteRaw(Environment.NewLine + "    <t:TimeZoneContext><t:TimeZoneDefinition Id=\"" + TimeZone.CurrentTimeZone.StandardName + "\"/></t:TimeZoneContext>" + Environment.NewLine);
        }