问题
Is it possible to get TimeZone and working hours of the users through EWS?
I am able to extract TZ and Working Hours for current user(Account with which the ExchangeService is initialized)
UserConfiguration usrConfig = UserConfiguration.Bind(service, "WorkHours", WellKnownFolderName.Calendar, UserConfigurationProperties.All);
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(new MemoryStream(usrConfig.XmlData));
XmlNodeList nlList = xmlDoc.GetElementsByTagName("WorkHoursVersion1");
Console.WriteLine(nlList.Item(0).InnerXml);
string str = nlList.Item(0).InnerXml;
But I am not able to extract the same information for other users.
回答1:
I use the GetUserAvailability operation.
Input is an array of users. Output includes an array of AttendeeAvailability, which contains a WorkingHours property, which itself includes TimeZone:
GetUserAvailabilityResults uars = service.GetUserAvailability(
new AttendeeInfo[] { new AttendeeInfo(smtpAddressOfUser, MeetingAttendeeType.Required, true), ... },
new TimeWindow(DateTime.Now, DateTime.Now.AddDays(1)),
AvailabilityData.FreeBusy
);
回答2:
If you have access to the other mailbox in question all you need to do is use the FolderId class specify the Mailbox you want to access and then use the FolderId overload of the UserConfiguration.Bind method eg
FolderId CalendarFolderId = new FolderId(Microsoft.Exchange.WebServices.Data.WellKnownFolderName.Calendar, "user@domain.onmicrosoft.com");
UserConfiguration usrConfig = UserConfiguration.Bind(service, "WorkHours", CalendarFolderId, UserConfigurationProperties.All);
Cheers Glen
回答3:
Have a look at Exchange Impersonation.
You can have a specific user account impersonate another user account and access their details without the need for their username and password.
string impName = @"impy";
string impPassword = @"password";
string impDomain = @"domain";
string impEmail = @"impy@domain.com";
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010);
service.Credentials = new NetworkCredential(impName, impPassword, impDomain);
service.AutodiscoverUrl(impEmail);
service.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, @"user@domain.com");
You should then be able to use UserConfiguration.Bind()
to do what you are after.
More references: http://msdn.microsoft.com/en-us/library/dd633680(v=exchg.80).aspx
来源:https://stackoverflow.com/questions/24478039/timezone-and-working-hours-for-users-through-ews