Пример #1
0
    private void BindTreeToDirectory(string dirPath, RadTreeNode parentNode, string exfolder)
    {
        string[] directories = Directory.GetDirectories(dirPath);
        foreach (string directory in directories)
        {
            if (!Path.GetFileName(directory).Contains("_svn") && !Path.GetFileName(directory).Contains(".svn"))
            {
                RadTreeNode node = new RadTreeNode(Path.GetFileName(directory));
                node.ImageUrl         = "/admin/images/folder.gif";
                node.ExpandedImageUrl = "/admin/images/folder.gif";
                node.ContextMenuID    = "MainContextMenu";
                node.Category         = "Folder";
                node.Value            = directory;

                parentNode.Nodes.Add(node);
                BindTreeToDirectory(directory, node, exfolder);
            }
        }

        string[] files = Directory.GetFiles(dirPath);
        foreach (string file in files)
        {
            if (!Path.GetFileName(file).Contains("_svn") && !Path.GetFileName(file).Contains(".svn"))
            {
                RadTreeNode node = new RadTreeNode(Path.GetFileName(file));
                node.ContextMenuID    = "ContextMenuFiles";
                node.Category         = "Files";
                node.Value            = file;
                node.ImageUrl         = "/admin/images/" + GetImageForExtension(Path.GetFileName(file).Substring(Path.GetFileName(file).IndexOf(".")));
                node.ExpandedImageUrl = "/admin/images/" + GetImageForExtension(Path.GetFileName(file).Substring(Path.GetFileName(file).IndexOf(".")));
                parentNode.Nodes.Add(node);
            }
        }

        if (exfolder != "")
        {
            if (exfolder == dirPath)
            {
                //string dir = exfolder.Substring(0, exfolder.LastIndexOf("\\"));
                foreach (RadTreeNode node in RadTreeView1.GetAllNodes())
                {
                    if (node.Value == exfolder)
                    {
                        node.ExpandParentNodes();
                        node.Selected = true;
                        node.Expanded = true;
                    }
                }
                //RadTreeNode cachedNodeClicked = RadTreeView1.FindNodeByValue(exfolder);
                //cachedNodeClicked.Expanded = true;
                //cachedNodeClicked.Selected = true;
            }
        }
    }