How to: Get Information About Direct Reports of the Current User's Manager

This example gets the direct reports of the current user’s manager, if any, and then displays information about each of the manager’s direct reports.

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, the GetManagerDirectReports procedure calls the GetExchangeUserManager() method to get the user’s manager, represented by an ExchangeUser object. If the current user has a manager, GetDirectReports() is called to return an AddressEntries collection that represents the address entries for all the direct reports of user’s manager. If the manager has no direct reports, GetDirectReports returns an AddressEntries collection that has a count of zero. Once the manager’s direct reports are obtained, GetManagerDirectReports writes information about each of the manager’s direct reports to the trace listeners of the Listeners collection.

Note Note

The logged-on user must be online for this method to return an AddressEntries collection; otherwise, GetDirectReports returns a null reference. For production code, you must test for the user being offline by using the _NameSpace.ExchangeConnectionMode property, or the _Account.ExchangeConnectionMode property for multiple Exchange scenarios.

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 GetManagerDirectReports()
    Outlook.AddressEntry currentUser =
    if (currentUser.Type == "EX")
        Outlook.ExchangeUser manager =
        if (manager != null)
            Outlook.AddressEntries addrEntries =
            if (addrEntries != null)
                foreach (Outlook.AddressEntry addrEntry
                    in addrEntries)
                    Outlook.ExchangeUser exchUser =
                    StringBuilder sb = new StringBuilder();
                    sb.AppendLine("Name: "
                        + exchUser.Name);
                    sb.AppendLine("Title: "
                        + exchUser.JobTitle);
                    sb.AppendLine("Department: "
                        + exchUser.Department);
                    sb.AppendLine("Location: "
                        + exchUser.OfficeLocation);

Other Resources