/// <summary> /// /// </summary> /// <returns></returns> public JsonResult ListBackupFiles() { string backupPath = GetBackupPath(); string backupUrl = GetBackupUrl(); DirectoryInfo di = new DirectoryInfo(backupPath); if (di.Exists) { FileInfo[] files = di.GetFiles(); if (files != null) { var list = files.Where(p => Path.GetExtension(p.Name).ToLower() == ".bak" || Path.GetExtension(p.Name).ToLower() == ".zip") .OrderByDescending(p => p.CreationTime) .Select(p => new { Name = p.Name, Size = FileSizeHelper.FormatFileSize(p.Length), CreateDate = p.CreationTime.ToString(Lang.Format_DateTime_String), Url = Url.Content(backupUrl + p.Name) }).ToList(); return(Json(list, JsonRequestBehavior.AllowGet)); } } return(null); }
/// <summary> /// 文件或目录列表 /// </summary> /// <param name="id"></param> /// <returns></returns> public ActionResult FileList(string id) { string path = Server.MapPath(logFolder); if (!string.IsNullOrEmpty(id)) { path = Path.Combine(path, id); } IList <FileListInfo> entities = new List <FileListInfo>(); DirectoryInfo di = new DirectoryInfo(path); if (di != null) { var dirs = di.GetDirectories(); if (dirs != null) { foreach (var d in dirs) { entities.Add(new FileListInfo { id = d.Name, name = d.Name, title = d.Name, pId = id, isParent = true }); } } if (!string.IsNullOrEmpty(id)) {//根目录文件不列出 var files = di.GetFiles(); if (files != null) { foreach (var f in files.OrderBy(f => f.Name)) { entities.Add(new FileListInfo { id = f.Name, name = string.Format("{0} [{1}]", f.Name, FileSizeHelper.FormatFileSize(f.Length)), title = string.Format("{0} [最后修改:{1}]", f.Name, f.LastWriteTime), pId = id, isParent = false }); } } } return(Json(entities)); } else { return(new EmptyResult()); } }