NerdyHearn
Home

IPhone SMS To Gmail

Consulting
Security Alerts

Blog
Software
Projects
Links
About
Contact

Blog
FriendFeed
Facebook
Flickr
Twitter
Toluu
Last.fm
Picasa
LinkedIn

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

Creating a reusable web client for PUT, POST, and DELETE in C#
Reading Digital Signatures from InfoPath Forms in MOSS 2007 and WSS 3.0 Workflow
Creating an Organizational Chart using C#: Part 2
Fixing "Error in loading DLL" in SharePoint
Creating an MD5 String Extension method in C#

Comments

Currently no comments.

Add A Comment

Name:


URL:


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


Comments:


Please enter the text from the image:



NerdyHearn - Latest tech news relating to C#, SharePoint, PHP, general development, and more. LiveNation Feed - Feeds of all your local artists, concerts, and events through your favorite RSS reader SaveMySerials - Protect yourself from theft, fire, natural disasters and more by recording your serial numbers Tweets2Mail - Backup and search your twitter stream from Gmail TimeSinceI - Track how long you have quit smoking, how long you have been married, or how long you have done anything.