NerdyHearn
Home
Blog

Contact
Mailing List

Software

Active Directory Products
Object Compare
Permission Compare

IPhone Products
Calls To Calendar
SMS To CSV
SMS To Gmail
Voicemail To Gmail

Sites
How Long For Me
SaveMySerials

Blog
Twitter

NerdyHearn - Blog


<< 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
{
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.

That's it for Part 1, I will continue with part 2 very soon.

UPDATE: Part 2 has now been published.

OrgChartin' Tom Out.

Tags

CSharp

Related Blogs

Writing console output from a Windows form in C#
SharePoint Web Services, .NET 3.5, and Authentication Issues
Fixing "Error in loading DLL" in SharePoint
Impersonating a user in ASP.NET
Reading Digital Signatures from InfoPath Forms in MOSS 2007 and WSS 3.0 Workflow

Comments

Currently no comments.

Add A Comment

Name:


URL:


Email Address: (not public, used to send notifications on further comments)


Comments:



Enter the text above, except for the 1st and last character:


NerdyHearn - Latest tech news relating to C#, ASP.NET, SharePoint, PHP, general development, and more. SaveMySerials - Protect yourself from theft, fire, natural disasters and more by recording your serial numbers