An organizational chart is something that many, well, organizations use. It is a very common request and often something that takes a long time for someone to create in something like Visio. Obviously the larger your company the more time-saving that is involved when these can be generated automatically.

This is the first part of a two-part series in which I would like to simply establish the basis, the technical layout, and the technologies that will be used to create the chart.

For the sake of this example, I will simply use a very simple Employee class, which will have their full name and their title. Each Employee instance can also hold any number of children Employees of the same type.

This class layout allows us to create the tree in concept, populate a tree-based Employee structure, and then populate the chart based on this layout.

The very simple code for the Employee class is as follows:

public class Employee
{
  private string m_Name = string.Empty;
  private string m_Title = string.Empty;
  private List m_Children = new List();

  public string Name
  {
    get
    {
      return m_Name;
    }
    set
    {
      m_Name = value;
    }
  }

  public string Title
  {
    get
    {
      return m_Title;
    }
    set
    {
      m_Title = value;
    }
  }

  public List Children
  {
    get
    {
      return m_Children;
    }
    set
    {
      m_Children = value;
    }
  }
}

This class can then be populated through a recursive call by whatever means you find necessary. The data populating this tree is most-often Active Directory or LDAP, but could also be SQL, XML, a Web Service, or anything else that is data-accessible.

Let’s use LDAP for our example, and the recursive call to populate our Employee tree would be something similiar to the following:

public Employee BuildTree(Employee Manager)
{
  // LDAP is out of the scope of this article, so let's assume this works properly
  List reports = LdapSearcherClass.FindDirectReports(Manager);
  foreach (Employee child in reports)
  {
    Manager.Children.Add(BuildTree(child));
  }
  return Manager;
}

To get the entire tree, we would simply call this as follows: Employee TopDog = BuildTree(new Employee(“TopDog Name”));

We now have the structure we need for the tree, and the method of populating this structure, which leaves us with an entirely populated tree of type Employee that we can use in Part 2 to actually draw the chart.