public void BuildDirectoryTreeNodes() { string previousPath = string.Empty; DirectoryTreeNode previousNode; DirectoryTreeNode rootNode; var rootDirectory = directoryList.First(); rootNode = new DirectoryTreeNode(rootDirectory.FullName, rootDirectory.Name, aceList.Where(ace => ace.FullName == rootDirectory.Name)); previousNode = rootNode; trvDirectories.Nodes.Add(rootNode); foreach (var directory in directoryList.Skip(1)) { if (previousNode.Name == directory.GetParent().FullName) { var node = new DirectoryTreeNode(directory.FullName, directory.Name, aceList.Where(ace => ace.FullName == directory.FullName)); previousNode.Nodes.Add(node); } else { previousNode = (DirectoryTreeNode)trvDirectories.Nodes.Find(directory.GetParent().FullName, true).FirstOrDefault(); if (previousNode != null) { var node = new DirectoryTreeNode(directory.FullName, directory.Name, aceList.Where(ace => ace.FullName == directory.FullName)); previousNode.Nodes.Add(node); } else { var node = new DirectoryTreeNode(directory.FullName, directory.Name, aceList.Where(ace => ace.FullName == directory.FullName)); previousNode.Nodes.Add(node); } } } }
private IEnumerable <DirectoryTreeNode> FindNodeByFolder(DirectoryTreeNode node, string search) { if (node.Text.ToLower().Contains(search.ToLower())) { yield return(node); } foreach (DirectoryTreeNode childNode in node.Nodes) { foreach (DirectoryTreeNode match in this.FindNodeByFolder(childNode, search)) { yield return(match); } } }
private IEnumerable <DirectoryTreeNode> FindNodeByIdentity(DirectoryTreeNode node, string search) { if (node.Acl.Where(ace => ace.Identity.AccountName.ToLower().Contains(search.ToLower())).Count() > 0) { yield return(node); } foreach (DirectoryTreeNode childNode in node.Nodes) { foreach (DirectoryTreeNode match in this.FindNodeByIdentity(childNode, search)) { yield return(match); } } }
public void RemoveFoldersWithoutAccess(DirectoryTreeNode node) { for (int i = 0; i < node.Nodes.Count; i++) { if (node.Nodes[i].GetNodeCount(false) > 0) { RemoveFoldersWithoutAccess((DirectoryTreeNode)node.Nodes[i]); } if (node.Nodes[i].Nodes.Count == 0 & ((DirectoryTreeNode)node.Nodes[i]).Acl.Count() == 0) { node.Nodes.Remove(node.Nodes[i]); i--; } } }