public async Task <ActionResult> UploadFiles(string applId, string FolderPath) { try { IEnumerable <string> values = Request.Headers.GetValues("ApplId"); string fileName = string.Empty; applId = values.FirstOrDefault().Split(',').First(); var rootPath = GetDirectory(applId, FolderPath); var _Path = Path.Combine(rootPath, applId); var files = new List <fileManagerFiles>(); if (!Directory.Exists(_Path)) { Directory.CreateDirectory(_Path); } for (int i = 0; i < Request.Files.Count; i++) { var file = Request.Files[i]; if (StringExtensions.ContainsOneCharacter(file.FileName)) { fileName = StringExtensions.TruncatePercents(file.FileName); var FileName = Path.Combine(rootPath, applId, fileName); file.SaveAs(FileName); } else { fileName = file.FileName; var FileName = Path.Combine(rootPath, applId, fileName); file.SaveAs(FileName); } var Info = new fileManagerFiles { FileName = fileName, Size = (file.ContentLength / 1024).ToString(), Extension = MimeMapping.GetMimeMapping(fileName), CreatedDate = DateTime.Now.ToString() }; files.Add(Info); } return(Json(files)); } catch (Exception) { return(Json(new { })); } }
public async Task <ActionResult> GetFiles(string ApplId, string FolderPath) { var _Dir = GetDirectory(ApplId, FolderPath); _Dir = Path.Combine(_Dir, ApplId); if (!Directory.Exists(_Dir)) { return(Json(new { files = new List <fileManagerFiles>() }, JsonRequestBehavior.AllowGet)); } var _Files = new DirectoryInfo(_Dir).GetFiles(); var InfoList = new List <fileManagerFiles>(); foreach (var item in _Files) { var file = new fileManagerFiles(); file.FileName = item.Name; file.Extension = MimeMapping.GetMimeMapping(item.Name); file.CreatedDate = item.CreationTime.ToString(); file.Size = (item.Length / 1024).ToString(); InfoList.Add(file); } return(Json(new { files = InfoList }, JsonRequestBehavior.AllowGet)); }