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?
 
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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.