Beispiel #1
0
 /// <summary>
 /// 文件浏览
 /// </summary>
 /// <returns></returns>
 public ActionResult FileList()
 {
     int pageIndex = PressRequest.GetQueryInt("page", 1);
     int pageSize = 50;
     if (string.IsNullOrEmpty(urlpath))
     {
         urlpath = rootpath;
     }
     var list = GetFilesList(urlpath);
     var model = new FilesModel();
     model.FoldList = list.FoldList.Select(fold => new FoldInfo
     {
         FoldName = fold.FoldName,
         FoldPath = fold.FoldPath,
         FileSystemInfosLength = fold.FileSystemInfosLength
     }).ToList();
     model.FileList = list.FileList.Select(f => new FileInfo
     {
         FileName = f.FileName,
         Extension = f.Extension,
         FileLength = f.FileLength,
         FilePath = f.FilePath,
         FileUrl = f.FileUrl
     }).ToList();
     if (model.FileList.Count == 0)
     {
         IPagedList<FoldInfo> foldlist = new PagedList<FoldInfo>(model.FoldList, pageIndex - 1, pageSize);
         model.FoldPageList.LoadPagedList<FoldInfo>(foldlist);
         model.FoldList = (List<FoldInfo>)foldlist;
     }
     string controller = RouteData.Values["controller"].ToString();
     string aera = "Admin";
     model.CurrentAction = "/" + aera + "/" + controller + "/" + "list";
     model.UserDirectory = new DirectoryInfo(Server.MapPath(urlpath));
     ViewBag.path = urlpath;
     ViewBag.UrlPath = System.IO.Path.GetFileName(Request.Url.AbsolutePath);
     model.PathUrl = GetPathUrl();
     return View(model);
 }
Beispiel #2
0
        public FilesModel GetFilesList(string path)
        {
            path = path.Replace("//", "/");
            var model = new FilesModel();
            if (!Directory.Exists(Server.MapPath(path)))
                return model;

            var dic = new DirectoryInfo(Server.MapPath(path));
            foreach (var d in dic.GetFileSystemInfos())
            {
                if (d is DirectoryInfo)
                {
                    var fold = new FoldInfo
                    {
                        FoldName = d.Name,
                        FoldPath = path,
                        FileSystemInfosLength = ((DirectoryInfo)d).GetFileSystemInfos().Length
                    };
                    model.FoldList.Add(fold);
                }
                else
                {
                    var file = new FileInfo
                    {
                        FileName = d.Name,
                        FileLength = FileHelper.ConvertUnit(((System.IO.FileInfo)d).Length),
                        Extension = d.Extension,
                        FileUrl = path + "/" + d.Name,
                        FilePath = d.FullName
                    };
                    model.FileList.Add(file);
                }
            }
            return model;
        }