/// <summary> /// Populate master tree /// </summary> /// <param name="relativePath"></param> /// <param name="node"></param> public void PopulateTree(string relativePath, FileTreeModel node) { var physicalPath = HttpContext.Current.Server.MapPath(relativePath); if (node.children == null) { node.children = new List<FileTreeModel>(); } var directory = new DirectoryInfo(physicalPath); //Loop through each subdirectory foreach (var d in directory.GetDirectories().Where(d => !d.Name.Equals(Configurations.ResizedFolder))) { var mediaPath = ToRelativePath(string.Format("{0}/{1}", relativePath, d.Name)); var t = new FileTreeModel { attr = new FileTreeAttribute { Id = mediaPath, Rel = "folder" }, data = d.Name, state = "closed" }; node.children.Add(t); } //Loop through each file in master directory foreach (var f in directory.GetFiles()) { var mediaPath = ToRelativePath(string.Format("{0}/{1}", relativePath, f.Name)); var t = new FileTreeModel { attr = new FileTreeAttribute { Id = mediaPath, Class = "jstree-leaf" }, data = f.Name, state = "open", }; if (Images.Contains(f.Extension)) { t.attr.Rel = "image"; t.attr.IsImage = true; } else { t.attr.Rel = "file"; } node.children.Add(t); } }
public JsonResult GetTreeData(string dir) { if (string.IsNullOrWhiteSpace(dir)) { var rootNode = new FileTreeModel { attr = new FileTreeAttribute { Id = _mediaServices.MediaDefaultPath, Rel = "home" }, state = "open", data = "MEDIA" }; var physicalPath = _mediaServices.MediaDefaultPath; _mediaServices.PopulateTree(physicalPath, rootNode); return Json(rootNode); } return Json(_mediaServices.PopulateChild(dir)); }
public List<FileTreeModel> PopulateChild(string relativePath) { var physicalPath = HttpContext.Current.Server.MapPath(relativePath); var directory = new DirectoryInfo(physicalPath); var children = directory.GetDirectories().Where(d => !d.Name.Equals(Configurations.ResizedFolder)) .Select(d => new FileTreeModel { attr = new FileTreeAttribute { Id = string.Format("{0}/{1}", ToRelativePath(relativePath), d.Name), Rel = "folder" }, data = d.Name, state = "closed" }).ToList(); foreach (var f in directory.GetFiles()) { var t = new FileTreeModel { attr = new FileTreeAttribute { Id = string.Format("{0}/{1}", ToRelativePath(relativePath), f.Name), Class = "jstree-leaf" }, data = f.Name, state = "open" }; if (Images.Contains(f.Extension)) { t.attr.Rel = "image"; t.attr.IsImage = true; } else { t.attr.Rel = "file"; } children.Add(t); } return children; }