Exemplo n.º 1
0
        public JsonResult List()
        {
            var filesPath = Server.MapPath("~/Files");
            var dirs      = Directory.EnumerateDirectories(filesPath, "*", SearchOption.AllDirectories)
                            .Select(d => d.Replace(filesPath, ""));

            var tree = new DirTree();

            WalkDirTree(new DirectoryInfo(filesPath), ref tree);

            return(Json(tree, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 2
0
        private void WalkDirTree(DirectoryInfo root, ref DirTree tree)
        {
            tree.name = root.Name;
            var subDirs = root.GetDirectories();

            if (subDirs.Count() > 0)
            {
                tree.dirs = new List <DirTree>(subDirs.Count());
                foreach (var dir in subDirs)
                {
                    var newTree = new DirTree {
                        name = dir.Name, dirs = null
                    };
                    tree.dirs.Add(newTree);
                    WalkDirTree(dir, ref newTree);
                }
            }
        }