Active Directory Products
Calls To Calendar
SMS To CSV
SMS To Gmail
Voicemail To Gmail
How Long For Me
<< Back To All Blogs
Creating an Organizational Chart using C#: Part 1
Wednesday, June 17th, 2009
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
m_Name = value;
public string Title
m_Title = value;
public List Children
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)
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.
That's it for Part 1, I will continue with part 2 very soon.
UPDATE: Part 2 has now been published.
OrgChartin' Tom Out.
Comparing XML files in C# Using Microsoft's Diff and Patch Tool
Enumerating a user secure certificate store in C#
Reading IPhone Text Messages using C# and SQLite
Calculating ISO 8601 Date formats in C#, C++, and Java
A quick way to find C++ method signatures for C# Interop
Currently no comments.
Add A Comment
Email Address: (not public, used to send notifications on further comments)
Enter the text above, except for the 1st and last character: