Solved

Mimic AD in a TreeView through C#

Posted on 2008-06-18
3
1,855 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 85

Accepted Solution

by:
oBdA earned 400 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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Recently, Microsoft released a best-practice guide for securing Active Directory. It's a whopping 300+ pages long. Those of us tasked with securing our company’s databases and systems would, ideally, have time to devote to learning the ins and outs…
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 …
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

696 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