共用方式為


取得目前使用者管理員的直接報告相關信息

這個範例會取得目前用戶經理的直接報告,如果有的話,然後顯示每個管理員直接報告的相關信息。

範例

注意事項

下列程式代碼範例是 Microsoft Office Outlook 2007 程式設計應用程式的摘錄。

在下列範例中,GetManagerDirectReports 程式會呼叫 GetExchangeUserManager () 方法來取得以 ExchangeUser 物件表示的使用者管理員。 如果目前使用者有管理員,則會呼叫 GetDirectReports () ,以傳回 AddressEntries 集合,代表使用者管理員之所有直接報表的地址專案。 如果管理員沒有直接報告, GetDirectReports 會 傳回計數為零的 AddressEntries 集合。 取得管理員的直接報告之後,GetManagerDirectReports 會將每個管理員直接報告的相關信息寫入接 聽程式 集合的追蹤接聽程式。

注意事項

登入的用戶必須上線,這個方法才能傳回 AddressEntries 集合;否則, GetDirectReports 會 傳回 Null 參考。 針對生產程序代碼,您必須使用 _NameSpace.ExchangeConnectionMode 屬性或多個 Exchange 案例的 _Account.ExchangeConnectionMode 屬性來測試使用者是否離線。

If you use Visual Studio to test this code example, you must first add a reference to the Microsoft Outlook 15.0 Object Library component and specify the Outlook variable when you import the Microsoft.Office.Interop.Outlook namespace. The using statement must not occur directly before the functions in the code example but must be added before the public Class declaration. The following line of code shows how to do the import and assignment in 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());
                }
            }
        }
    }
}

另請參閱