该示例获取当前用户的经理的直接下属(如果有),然后显示每名经理的直接下属的信息。
示例
注意
下面的代码示例摘录自 Microsoft Office Outlook 2007 应用程序编程。
在下面的代码示例中,GetManagerDirectReports 过程调用 GetExchangeUserManager() 方法,以获取用户的经理(由 ExchangeUser 对象表示)。 如果当前用户有经理,此代码示例便会调用 GetDirectReports(),以返回 AddressEntries 集合(表示用户的经理的所有直接下属的地址条目)。 如果经理没有直接下属,GetDirectReports 返回计数为零的 AddressEntries 集合。 获取经理的直接下属后,GetManagerDirectReports 将每个经理的直接下属的相关信息写入 Listeners 集合的跟踪侦听器中。
注意
已登录用户必须处于联机状态,此方法才能返回 AddressEntries 集合;否则,GetDirectReports 返回空引用。 对于生产代码,您必须针对多种 Exchange 方案,使用 _NameSpace.ExchangeConnectionMode 属性或 _Account.ExchangeConnectionMode 属性对处于脱机状态下的用户进行测试。
如果使用 Visual Studio 测试此代码示例,必须先添加对 Microsoft Outlook 15.0 对象库组件的引用,并在导入 Microsoft.Office.Interop.Outlook 命名空间时指定 Outlook 变量。 不得将 using 语句直接添加到此代码示例中的函数前面,这个语句必须后跟公共类声明。 下面的代码行演示了如何在 C# 中执行导入和分配。
using Outlook = Microsoft.Office.Interop.Outlook;
private void GetManagerDirectReports()
{
Outlook.AddressEntry currentUser =
Application.Session.CurrentUser.AddressEntry;
if (currentUser.Type == "EX")
{
Outlook.ExchangeUser manager =
currentUser.GetExchangeUser().GetExchangeUserManager();
if (manager != null)
{
Outlook.AddressEntries addrEntries =
manager.GetDirectReports();
if (addrEntries != null)
{
foreach (Outlook.AddressEntry addrEntry
in addrEntries)
{
Outlook.ExchangeUser exchUser =
addrEntry.GetExchangeUser();
StringBuilder sb = new StringBuilder();
sb.AppendLine("Name: "
+ exchUser.Name);
sb.AppendLine("Title: "
+ exchUser.JobTitle);
sb.AppendLine("Department: "
+ exchUser.Department);
sb.AppendLine("Location: "
+ exchUser.OfficeLocation);
Debug.WriteLine(sb.ToString());
}
}
}
}
}