Export (0) Print
Expand All

How to: Get Information About All Distribution Lists of Which the Current User is a Member

This example uses the GetMemberOfList() method to get information about all distribution lists of which the current user is a member.

Programming Applications for Office Outlook 2007

The following code example is an excerpt from Programming Applications for Microsoft Office Outlook 2007, from Microsoft Press (ISBN 9780735622494, copyright Microsoft Press 2007, all rights reserved).

Buy this book

Sample chapters

In the following example, GetCurrentUserMembership calls the GetMemberOfList method to get an AddressEntries collection for all distribution lists of which the Exchange user is a member. If the user is not a member of any distribution lists, GetMemberOfList returns an AddressEntries collection that has a count of zero. The user must be online for GetMemberOfList to return an AddressEntries collection; otherwise, GetMemberOfList returns a null reference. GetCurrentUserMembership uses the GetExchangeUser() method, which returns the current ExchangeUser object, to test whether the user is online. Once the address entries are obtained, the example writes information about each of the user’s distribution lists to the trace listeners of the Listeners collection.

If you use Microsoft Visual Studio to test this code example, you must first add a reference to the Microsoft Outlook 14.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);
                }
            }
        }
    }
}

Other Resources

Community Additions

ADD
Show:
© 2014 Microsoft