Пример #1
0
        // GET: /File/ListFiles?folderPath=path
        public ActionResult ListFiles(string folderPath)
        {
            ViewBag.FolderPath = null;
            if (!_validateRest.Validate(folderPath))
            {
                ViewBag.FolderPath = "Folder path is invalid.";
                return(View("Index"));
            }

            Session["folderPath"] = folderPath;
            JsTreeNodeModel root = new JsTreeNodeModel
            {
                Text  = folderPath.Substring(folderPath.LastIndexOf(@"\", StringComparison.Ordinal) + 1),
                State = new JsTreeNodeState()
            };

            DirectorySearch(folderPath, root, _fileRest);
            return(View("ListFiles", null, JsonConvert.SerializeObject(root)));
        }
Пример #2
0
        private static void DirectorySearch(string folderPath, JsTreeNodeModel root, IFileRest fileRest)
        {
            root.Children     = new List <JsTreeNodeModel>();
            root.State.Opened = true;

            foreach (string fileName in Directory.GetFiles(folderPath))
            {
                if (AllowedExtensions != null && AllowedExtensions.Any(ext => fileName.EndsWith(ext)))
                {
                    BaseFile file = fileRest.Get(fileName);

                    FileInfo fileInfo = new FileInfo(fileName);
                    root.Children.Add(new JsTreeNodeModel
                    {
                        Text = fileInfo.Name,
                        Type = file == null ? "file_new" : "file_added",
                        Attr = new JsTreeAttr {
                            DataFilename = fileInfo.FullName
                        },
                        State = new JsTreeNodeState()
                    });
                }
            }

            foreach (string directoryName in Directory.GetDirectories(folderPath))
            {
                DirectoryInfo directoryInfo = new DirectoryInfo(directoryName);

                JsTreeNodeModel node = new JsTreeNodeModel
                {
                    Text  = directoryInfo.Name,
                    State = new JsTreeNodeState()
                };

                DirectorySearch(directoryName, node, fileRest);

                root.Children.Add(node);
            }
        }
Пример #3
0
        private static void DirectorySearch(string folderPath, JsTreeNodeModel root, IFileRest fileRest)
        {
            root.Children = new List<JsTreeNodeModel>();
            root.State.Opened = true;

            foreach (string fileName in Directory.GetFiles(folderPath))
            {
                if (AllowedExtensions != null && AllowedExtensions.Any(ext => fileName.EndsWith(ext)))
                {
                    BaseFile file = fileRest.Get(fileName);

                    FileInfo fileInfo = new FileInfo(fileName);
                    root.Children.Add(new JsTreeNodeModel
                    {
                        Text = fileInfo.Name,
                        Type = file == null ? "file_new" : "file_added",
                        Attr = new JsTreeAttr { DataFilename = fileInfo.FullName },
                        State = new JsTreeNodeState()
                    });
                }
            }

            foreach (string directoryName in Directory.GetDirectories(folderPath))
            {
                DirectoryInfo directoryInfo = new DirectoryInfo(directoryName);

                JsTreeNodeModel node = new JsTreeNodeModel
                {
                    Text = directoryInfo.Name,
                    State = new JsTreeNodeState()
                };

                DirectorySearch(directoryName, node, fileRest);

                root.Children.Add(node);
            }
        }
Пример #4
0
        // GET: /File/ListFiles?folderPath=path
        public ActionResult ListFiles(string folderPath)
        {
            ViewBag.FolderPath = null;
            if (!_validateRest.Validate(folderPath))
            {
                ViewBag.FolderPath = "Folder path is invalid.";
                return View("Index");
            }

            Session["folderPath"] = folderPath;
            JsTreeNodeModel root = new JsTreeNodeModel
            {
                Text = folderPath.Substring(folderPath.LastIndexOf(@"\", StringComparison.Ordinal) + 1),
                State = new JsTreeNodeState()
            };

            DirectorySearch(folderPath, root, _fileRest);
            return View("ListFiles", null, JsonConvert.SerializeObject(root));
        }