3

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.

Styx
  • 9,863
  • 8
  • 43
  • 53
HarshJain
  • 327
  • 1
  • 4
  • 12

3 Answers3

4

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
    );
Steve B
  • 36,818
  • 21
  • 101
  • 174
tjleigh
  • 1,134
  • 1
  • 10
  • 23
0

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

Glen Scales
  • 20,495
  • 1
  • 20
  • 23
  • When I do this, I get this error {"The SMTP address has no mailbox associated with it."} – HarshJain Jun 30 '14 at 07:34
  • That error would indicate your not using the Primary SMTP for the Mailbox. Can you do a resolvename wit the same SMTP address eg NameResolutionCollection nc = service.ResolveName("user@domain.onmicrosoft.com", ResolveNameSearchLocation.DirectoryOnly, true); FolderId CalendarFolderId = new Data.FolderId(Microsoft.Exchange.WebServices.Data.WellKnownFolderName.Calendar, nc[0].Mailbox.Address); UserConfiguration usrConfig = UserConfiguration.Bind(service, "WorkHours", CalendarFolderId, UserConfigurationProperties.All); – Glen Scales Jun 30 '14 at 22:50
0

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

Brett McKenzie
  • 545
  • 4
  • 12