468,554 Members | 1,249 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,554 developers. It's quick & easy.

Retrieving Active Directory Hierarchies through ASP.NET and C#

Hello Guys,

I am developing a web application to manage Active Directory resources, and one of my tasks is to map Organizational Units hierarchy into a SQL Server database. Let's suppose that I have the following OU hierarchy in my Active Direcoty:

1. NewYork
-----1.1 HR_Department
----------1.1.1 Computers
----------1.1.2 Users
-----1.2 SALES_Department
----------1.2.1 Computers
----------1.2.2 Users
-----1.3 So on.....
2. Chicago
-----2.1 HR_Department
----------1.1.1 Computers
----------1.1.2 Users
-----2.2 SALES_Department
----------2.1.1 Computers
----------2.1.2 Users
-----2.3 So on....

I designed the following table into SQL Server in order to reach the AD hierarchy:

// Just an integer ID to identify the row.

// Name of OU that comes from AD.

ParentOUId INT
// Id of the parent OU to create as many levels as necessary.

The idea is to create a recursive table to store the hierarchy in a flexible way that there won't be any limitations in terms of creating as many sub OU as necessary. At this point goes my issue: I am having problems to create a C# function to return whether a OU already exists or not.

Unfortunately Active Directory does not provide me a property that indicates who is parent OU. I can only identify the object structure by the distinguishedName property, which acording to my example returns something like:

OU=Computers,OU=HR_Deparment, OU=NewYork, DC=....

From this string, I convert it to an array:

[0] Computers
[1] HR_Department
[2] NewYork

From now on, I am stuck. I don't know how to create a recursive function to return and create the AD Hierarchy in my context.

Could anyone help handle this?

Thank you very much for you attention!
Jul 18 '08 #1
0 1142

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

9 posts views Thread by Mario Rodriguez | last post: by
reply views Thread by Buddy Ackerman | last post: by
1 post views Thread by Andrew | last post: by
1 post views Thread by tangus via DotNetMonster.com | last post: by
reply views Thread by Chung Leong | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.