Getting direct reports under another manager's direct reports list

I've been trying to figure out how to do this but I'm always met with a bump on the road. What I'm trying to do is to get the reporting people under my manager's direct reports list; so for example, "Alex" is a direct report under my manager, however, when you go into his organization you see that he also has direct reports that report directly to him - I am trying to get "those" reports not only from his side but from anyone else in the list that has direct reports as well. What is needed for me to effectively execute that idea? Many thanks!

This is my code to only get Direct Reports under my manager tree:
    public void GetManagerDirectReports()
        {
            Application App = new Application();
            AddressEntry currentUser = App.Session.CurrentUser.AddressEntry;
            if (currentUser.Type == "EX")
            {
                ExchangeUser manager = currentUser.GetExchangeUser().GetExchangeUserManager();
                if (manager != null)
                {
                    AddressEntries addrEntries = manager.GetDirectReports();
                    if (addrEntries != null)
                    {
                        foreach (AddressEntry addrEntry in addrEntries)
                        {
                            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("Email: "
                                + exchUser.PrimarySmtpAddress);
                            Debug.WriteLine(sb.ToString());
                            Console.WriteLine(sb.ToString());
                            Console.ReadLine();
                        }
                    }
                }
            }
        }

Open in new window

Lazaro RondonAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AndyAinscowFreelance programmer / ConsultantCommented:
It sounds like you need recursion.

Roughly:
GetInfo(topManager)


and
GetInfo(MyObject ob)
{
  //Get the info
  ForEach(MyObject child in ob.Children())
  {
    GetInfo(child);
  }
}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Lazaro RondonAuthor Commented:
That is correct Andy, I do indeed need recursion because I need it to loop back to me every time it finds a parent and child. Now, and excuse my dumb question, how do I structure your code snippet in order for me to get the managers and direct reports of those managers?
0
AndyAinscowFreelance programmer / ConsultantCommented:
You have
ExchangeUser manager =
and
ExchangeUser exchUser

so I guess you need to replace MyObject with ExchangeUser
0
AndyAinscowFreelance programmer / ConsultantCommented:
Recursion is needed to loop through children of parent and the children of each child.....
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Exchange

From novice to tech pro — start learning today.