private static void GetOUTreeNode(OuTreeNode root, XmlNode tempXml) { foreach (XmlNode xmlNode in tempXml.ChildNodes) { OuTreeNode childNode = new OuTreeNode() { Name = XmlConvert.DecodeName(xmlNode.Attributes["name"].Value), Id = xmlNode.Attributes["guid"].Value }; root.Children.Add(childNode); GetOUTreeNode(childNode, xmlNode); } }
private static OuTreeNode BuildOuTree(XmlDocument tempXml) { OuTreeNode root = new OuTreeNode(); using (Domain domain = Domain.GetCurrentDomain()) { root.Name = domain.Name; } GetOUTreeNode(root, tempXml.FirstChild); return root; }
private static void print(OuTreeNode tree, int depth) { depth += 1; StringBuilder builder = new StringBuilder(); for (int i = 0; i < depth; i++) { builder.Append(" "); } builder.Append(tree.Name); Console.WriteLine(builder.ToString()); if (tree.Children.Count > 0) { foreach (OuTreeNode node in tree.Children) { print(node, depth); } } }
private static void GetOuTreeNormal(OuTreeNode parentNode, DirectoryEntry parentDirectoryEntry) { using (DirectorySearcher ds = new DirectorySearcher(parentDirectoryEntry)) { ds.Filter = "(objectClass=organizationalunit)"; ds.SearchScope = SearchScope.OneLevel; try { using (SearchResultCollection result = ds.FindAll()) { foreach (SearchResult entry in result) { string name = entry.GetDirectoryEntry().Properties["Name"].Value.ToString(); byte[] bytes = entry.GetDirectoryEntry().Properties["ObjectGuid"].Value as byte[]; Guid id = new Guid(bytes); OuTreeNode node = new OuTreeNode() { Name = name, Id = id.ToString() }; parentNode.Children.Add(node); using (DirectoryEntry child = entry.GetDirectoryEntry()) { GetOuTreeNormal(node, child); } } } } catch (Exception e) { throw e; } } }
public static OuTreeNode GetOuTreeNormal() { string domainName = string.Empty; OuTreeNode rootNode = null; using (Domain domain = Domain.GetCurrentDomain()) { domainName = domain.Name; rootNode = new OuTreeNode() { Name = domainName }; GetOuTreeNormal(rootNode, domain.GetDirectoryEntry()); } return rootNode; }