private void ProcessTaskVersion(HttpRequestBase req, Ruanal.WebDomain.Model.TaskVersion model) { if (string.IsNullOrWhiteSpace(model.VersionNO)) { model.VersionNO = DateTime.Now.ToString("vyyyy.MM.dd_HH.mm"); } HttpPostedFileBase downloadfile = null; if (req.Files.Count > 0) { downloadfile = req.Files[0]; } if (downloadfile == null || downloadfile.ContentLength == 0) { throw new Ruanal.WebDomain.MException("请上传文件"); } string filename = model.TaskId + "_" + DateTime.Now.ToString("yyMMddHHmmss") + ".zip"; string pathname = Pub.GetConfig("taskDllFile", "~/taskDllFile"); string path = Server.MapPath(pathname); if (!System.IO.Directory.Exists(path)) { System.IO.Directory.CreateDirectory(path); } string filefullname = System.IO.Path.Combine(path, filename); downloadfile.SaveAs(filefullname); model.FilePath = System.IO.Path.Combine(pathname.TrimStart('~'), filename).Replace("\\", "/"); model.FileSize = downloadfile.ContentLength / 1024m; }
public JsonResult DeleteTaskPackage(int keeppackagecount = 10) { var data = systool.GetTasksTopVersions(keeppackagecount); string pathname = Pub.GetConfig("taskDllFile", "~/taskDllFile"); string path = Server.MapPath(pathname); List <string> keepfiles = new List <string>(); foreach (var a in data) { foreach (var b in a.Value) { var fn = b.FilePath.Split("/\\".ToArray()).Last(); keepfiles.Add(fn.ToLower()); } } int count = 0; if (System.IO.Directory.Exists(path)) { System.IO.DirectoryInfo directory = new System.IO.DirectoryInfo(path); foreach (var f in directory.GetFiles()) { if (keepfiles.Contains(f.Name.ToLower())) { continue; } f.Delete(); count++; } } return(Json(new JsonEntity() { code = 1, msg = "删除" + count + "条" })); }