Exemple #1
0
        public static folder getRootFloder(DirectoryInfo di)
        {
            folder f = new folder();

            FileInfo[]  fis   = di.GetFiles();
            List <file> files = new List <file>();

            foreach (var item in fis)
            {
                file file = getFile(item);
                files.Add(file);
            }
            DirectoryInfo[] dis = di.GetDirectories();
            List <folder>   fs  = new List <folder>();

            foreach (var item in dis)
            {
                folder folder = getRootFloder(item);
                fs.Add(folder);
            }
            f.name         = di.Name;
            f.ModifiedDate = di.LastWriteTime;
            f.files        = files;
            f.folders      = fs;
            return(f);
        }
Exemple #2
0
        /// <summary>
        /// 获取文件夹下所有文件和文件夹,不包含子目录
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public static folder getFloder(string path)
        {
            folder        f  = new folder();
            DirectoryInfo di = new DirectoryInfo(path);

            FileInfo[]  fis   = di.GetFiles();
            List <file> files = new List <file>();

            foreach (var item in fis)
            {
                file file = getFile(item);
                files.Add(file);
            }
            DirectoryInfo[] dis = di.GetDirectories();
            List <folder>   fs  = new List <folder>();

            foreach (var item in dis)
            {
                folder folder = new folder();
                folder.ModifiedDate  = item.LastWriteTime;
                folder.CreatDateTime = item.CreationTime;
                folder.name          = item.Name;
                folder.fileLength    = getFileLength(item.FullName);
                folder.folderLength  = getFolderLength(item.FullName);
                folder.size          = getFolderSize(item.FullName);
                fs.Add(folder);
            }
            f.name          = di.Name;
            f.ModifiedDate  = di.LastWriteTime;
            f.files         = files;
            f.folders       = fs;
            f.CreatDateTime = di.CreationTime;
            f.fileLength    = getFileLength(di.FullName);
            f.folderLength  = getFolderLength(di.FullName);
            f.size          = getFolderSize(di.FullName);
            return(f);
        }
Exemple #3
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";

            string order        = context.Request["order"];
            string fileRootPath = ConfigurationManager.AppSettings["filePath"];
            string path         = context.Request["path"];
            string search       = context.Request["search"];
            string rootPath     = fileRootPath;

            path = rootPath + "\\" + path;
            PostJSON             p   = new PostJSON();
            JavaScriptSerializer jss = new JavaScriptSerializer();

            if (!Directory.Exists(rootPath))//如果用户根路径不存在则创建
            {
                Directory.CreateDirectory(rootPath);
            }
            if (path.IndexOf("..\\") == -1 && path.IndexOf("../") == -1)//如果包含上一级符号则屏蔽
            {
                if (Directory.Exists(path))
                {
                    folder folder = new folder();
                    folder = fileBLL.getFloder(path);
                    switch (order)
                    {
                    case "order_nameascending": folder.sortByName(); break;

                    case "order_sizeascending": folder.sortBySize(); break;

                    case "order_ModifiedDateascending": folder.sortByModifiedDate(); break;

                    case "order_CreatDateTimeascending": folder.sortByCreatDateTime(); break;

                    case "order_namedesc": folder.sortByNameDesc(); break;

                    case "order_sizedesc": folder.sortBySizeDesc(); break;

                    case "order_ModifiedDatedesc": folder.sortByModifiedDateDesc(); break;

                    case "order_CreatDateTimedesc": folder.sortByCreatDateTimeDesc(); break;

                    default:
                        break;
                    }
                    p.obj = folder;
                }
                else
                {
                    p.isError  = true;
                    p.errorMsg = "指定的目录不存在!";
                }
            }
            else
            {
                p.isError  = false;
                p.errorMsg = "不允许使用上一级符号";
            }



            context.Response.Write(jss.Serialize(p));
            context.Response.End();
        }