Updated Appointment via EWS shows UTC instead of local TZ

混江龙づ霸主 提交于 2019-12-11 10:50:54

问题


I have researched for this issue and am unable to find a solution.

The SO post TimeZone change to UTC while updating the Appointment referred to the same problem, but I've tested the solution and its not working.

Here is what's wrong:

Does anyone have a solution? The time is correctly reflected on Outlook, Emails etc. It's just that the text shown is misleading to people and causing confusion.

*Note that the code below can be copied and pasted into a console app for testing.

var timezone = TimeZoneInfo.FindSystemTimeZoneById("Tokyo Standard Time");

var service = new ExchangeService(ExchangeVersion.Exchange2013, timezone);
service.Credentials = new NetworkCredential("myemail@mydomain.com", "mypassword");
service.Url = new Uri("https://outlook.office365.com/Ews/Exchange.asmx");

var meeting1 = new Appointment(service);
meeting1.Subject = "Test Meeting";
meeting1.Body = "Test body";
meeting1.Start = new DateTime(2013, 8, 22, 9, 0, 0); //my default time is GMT+8
meeting1.End = meeting1.Start.AddHours(2);
meeting1.Location = "Conf Room";
meeting1.RequiredAttendees.Add("someone@outlook.com");

meeting1.Save(SendInvitationsMode.SendToAllAndSaveCopy);

Console.WriteLine("1st invite sent");

var id = meeting1.Id.ToString();


System.Threading.Thread.Sleep(5000); //break for a while...

//re-fetch the appointment
var meeting2 = Appointment.Bind(service, new ItemId(id),
        new PropertySet(BasePropertySet.IdOnly, AppointmentSchema.Start,                                          
              AppointmentSchema.End, AppointmentSchema.StartTimeZone,  
              AppointmentSchema.EndTimeZone, AppointmentSchema.TimeZone));

Console.WriteLine( meeting2.StartTimeZone ); //shows Tokyo Standard Time correctly.

meeting2.StartTimeZone = TimeZoneInfo.FindSystemTimeZoneById("Tokyo Standard Time");
meeting2.EndTimeZone = TimeZoneInfo.FindSystemTimeZoneById("Tokyo Standard Time");
meeting2.Start = new DateTime(2013,8,23, 9,0,0, DateTimeKind.Unspecified);
meeting2.End = meeting2.Start.AddHours(2);
meeting2.Subject = "Updated Test Meeting";
meeting2.Update(ConflictResolutionMode.AlwaysOverwrite, SendInvitationsOrCancellationsMode.SendToAllAndSaveCopy);


meeting2.Load(new PropertySet(BasePropertySet.IdOnly, AppointmentSchema.Start,
    AppointmentSchema.End, AppointmentSchema.StartTimeZone,  
            AppointmentSchema.EndTimeZone, AppointmentSchema.TimeZone, 
            AppointmentSchema.Body, AppointmentSchema.NormalizedBody,AppointmentSchema.TextBody));


Console.WriteLine( meeting2.StartTimeZone ); //shows Tokyo Standard Time correctly. 

回答1:


I've been having the same issue as we're using ExchangeVersion.Exchange2010_SP2 but i'm managed to get round this using:

appointment.Save(SendInvitationsMode.SendToNone);
// to fix the issue of updating appointment sets timezone to UTC, we use ExchangeVersion.Exchange2007_SP1
service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
service.UseDefaultCredentials = false;
service.Credentials = new WebCredentials(Account, Password);
service.Url = new Uri(url);
service.Timeout = 600000;


来源:https://stackoverflow.com/questions/18356896/updated-appointment-via-ews-shows-utc-instead-of-local-tz

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!