public JsonResult GetChildreenTree(string dir, int mID) { SetModuleId(mID); var rootNode = new FilesTree { attr = new FilesTreeAttribute { id = dir }, data = dir.Substring(1) }; var rootPath = dir; rootNode.attr.id = rootPath; PopulateTree(rootPath, rootNode); return Json(rootNode.children); }
public JsonResult GetTreeData(int mID) { SetModuleId(mID); var rootPath = PortalSettings.PortalFullPath; var rootNode = new FilesTree { attr = new FilesTreeAttribute { id = rootPath }, data = rootPath }; rootNode.attr.id = rootPath; PopulateTree(rootPath, rootNode); return Json(rootNode); }
/// <summary> /// A method to populate a TreeView with directories, subdirectories, etc /// </summary> /// <param name="dir">The path of the directory</param> /// <param name="node">The "master" node, to populate</param> public void PopulateTree(string dir, FilesTree node) { var directory = new DirectoryInfo(Request.MapPath(dir)); if (node.children == null && directory.GetDirectories().Length > 0) { node.children = new List<FilesTree>(); } // get the information of the directory // loop through each subdirectory foreach (var t in from d in directory.GetDirectories() let dirName = string.Format("{0}/{1}", dir, d.Name) select new FilesTree { attr = new FilesTreeAttribute { id = dirName }, data = d.Name, state = "closed"} into t where node.children != null select t) { node.children.Add(t); // add the node to the "master" node } // lastly, loop through each file in the directory, and add these as nodes //foreach (var f in directory.GetFiles()) { // // create a new node // var t = new FilesTree {attr = new FilesTreeAttribute {id = f.FullName}, data = f.Name}; // // add it to the "master" // node.children.Add(t); //} }