共用方式為


取得目前使用者為其成員之所有通訊組清單的相關信息

此範例使用 GetMemberOfList () 方法來取得目前使用者為其成員之所有通訊組清單的相關信息。

範例

注意事項

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

在下列範例中,GetCurrentUserMembership 會呼叫 GetMemberOfList 方法,針對 Exchange 使用者為其成員的所有通訊組清單取得 AddressEntries 集合。 如果使用者不是任何通訊組清單的成員, GetMemberOfList 會傳回計數為零的 AddressEntries 集合。 用戶必須在在線 ,GetMemberOfList 才能傳回 AddressEntries 集合;否則, GetMemberOfList 會傳回 Null 參考。 GetCurrentUserMembership 會使用 GetExchangeUser () 方法,以傳回目前的 ExchangeUser 物件,以測試使用者是否在在線。 取得地址項目之後,此範例會將每個用戶通訊組清單的相關信息寫入接聽程式集合的追蹤接 程式。

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 GetCurrentUserMembership()
{
    Outlook.AddressEntry currentUser =
        Application.Session.CurrentUser.AddressEntry;
    if (currentUser.Type == "EX")
    {
        Outlook.ExchangeUser exchUser =
            currentUser.GetExchangeUser();
        if (exchUser != null)
        {
            Outlook.AddressEntries addrEntries =
                exchUser.GetMemberOfList();
            if (addrEntries != null)
            {
                foreach (Outlook.AddressEntry addrEntry
                    in addrEntries)
                {
                    Debug.WriteLine(addrEntry.Name);
                }
            }
        }
    }
}

另請參閱