2014-06-29 20 views
1

是否有可能通过EWS获取用户的时区和工作时间?通过EWS为用户提供时区和工作时间

我能提取TZ和工作时间为当前用户(与该ExchangeService初始化帐户)

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; 

但我不能够提取其他用户相同的信息。

回答

3

我使用GetUserAvailability操作。

输入是一组用户。输出包括array of AttendeeAvailability,其中包含了WorkingHours属性,它本身包括时区:

GetUserAvailabilityResults uars = service.GetUserAvailability(
    new AttendeeInfo[] { new AttendeeInfo(smtpAddressOfUser, MeetingAttendeeType.Required, true), ... }, 
    new TimeWindow(DateTime.Now, DateTime.Now.AddDays(1)), 
    AvailabilityData.FreeBusy 
    ); 
0

如果你有机会到有问题的其他邮箱,所有你需要做的就是使用FolderId类指定要访问,然后使用UserConfiguration.Bind方法如

 FolderId CalendarFolderId = new FolderId(Microsoft.Exchange.WebServices.Data.WellKnownFolderName.Calendar, "[email protected]"); 
     UserConfiguration usrConfig = UserConfiguration.Bind(service, "WorkHours", CalendarFolderId, UserConfigurationProperties.All); 
的FolderId超载邮箱

Cheers Glen

+0

{“ SMTP地址没有与之关联的邮箱”}当我这样做,我得到这个错误 – HarshJain

+0

该错误将表明您不使用邮箱的主SMTP。您可以使用相同的SMTP地址执行resolvename,例如: NameResolutionCollection nc = service.ResolveName(“[email protected]”,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); –

0

看一看Exchange Impersonation

您可以让一个特定的用户帐户冒充另一个用户帐户并访问他们的详细信息,而不需要他们的用户名和密码。

string impName = @"impy"; 
string impPassword = @"password"; 
string impDomain = @"domain"; 
string impEmail = @"[email protected]"; 

ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010); 
service.Credentials = new NetworkCredential(impName, impPassword, impDomain); 
service.AutodiscoverUrl(impEmail); 

service.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, @"[email protected]"); 

然后,您应该能够使用UserConfiguration.Bind()做你所追求的。

更多的参考资料: http://msdn.microsoft.com/en-us/library/dd633680(v=exchg.80).aspx

相关问题