?
Solved

Mimic AD in a TreeView through C#

Posted on 2008-06-18
3
Medium Priority
?
1,958 Views
Last Modified: 2008-09-03
What I'm trying to do is query our Domain Controller for all of the Active Directory objects and mimic that view in a C# TreeView. The code I attached below ~works~ but it takes forever to load and hogs up system resources. Is there a simpler way to do this? I just need to make the TreeView look exactly like AD (Ou's, users' computer's, etc). Is there a better way to do this than below?


private static TreeNode RecursiveComputeLeafNodes(String ou, TreeNode nodes)
        {
            DirectoryEntry entry = new DirectoryEntry();
            if (ou.Equals(""))
                entry = new DirectoryEntry("LDAP://dc=corp,dc=pizzagalli,dc=com");
            else 
                entry = new DirectoryEntry(ou);
            //DirectorySearcher mySearcher = new DirectorySearcher(entry);
            //mySearcher.Filter = "(objectClass=computer)";
            foreach (System.DirectoryServices.DirectoryEntry child in entry.Children)
            {
                if (child.Properties.Count != 0)
                {
                    TreeNode newTreeNode = new TreeNode(child.Name.ToString().Remove(0,3));
                    nodes.Nodes.Add(RecursiveComputeLeafNodes(child.Path.ToString(), newTreeNode));
                }
                else
                {
                    String treeName = child.Name.ToString().Remove(0, 3);
                    nodes.Nodes.Add(new TreeNode(treeName));
                }
            }
            return nodes;
        }

Open in new window

0
Comment
Question by:invisiblekhaos2
1 Comment
 
LVL 85

Accepted Solution

by:
oBdA earned 1600 total points
ID: 21816139
Probably; I'm not a programmer, but you might have a look at these for starters, as they might keep you from reinventing the wheel:

Directory Object Picker
http://msdn.microsoft.com/en-us/library/ms675899(VS.85).aspx

Using the Windows 2000/XP Object Selection Dialog
http://www.codeproject.com/KB/winsdk/bfobjectselection2.aspx?display=Print
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Had a business requirement to store the mobile number in an environmental variable. This is just a quick article on how this was done.
This process allows computer passwords to be managed and secured without using LAPS. This is an improvement on an existing process, enhanced to store password encrypted, instead of clear-text files within SQL
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question