public ActionResult PostFile(string postData, string keyValue) { FileInfoEntity fileInfoEntity = new FileInfoEntity(); FileInfoBLL fileInfoBLL = new FileInfoBLL(); fileInfoBLL.DeleteFileByRecId(keyValue);//删除原有附件 var dt = JsonConvert.DeserializeObject <List <FileInfoEntity> >(postData); List <FileInfoEntity> projects = dt; string dir = string.Format("~/Resource/{0}/{1}", "ht/images", DateTime.Now.ToString("yyyyMMdd")); if (Directory.Exists(Server.MapPath(dir)) == false)//如果不存在就创建文件夹 { Directory.CreateDirectory(Server.MapPath(dir)); } foreach (FileInfoEntity item in dt) { var filepath = Server.MapPath(item.FilePath); if (System.IO.File.Exists(filepath)) { string sufx = System.IO.Path.GetExtension(filepath); string newFileName = Guid.NewGuid().ToString() + sufx; string newFilePath = dir + "/" + newFileName; System.IO.File.Copy(filepath, Server.MapPath(newFilePath)); item.FilePath = newFilePath; } item.RecId = keyValue; item.FileId = Guid.NewGuid().ToString(); fileInfoBLL.SaveForm("", item); } fileInfoBLL.SaveForm("", fileInfoEntity); return(Success("操作成功。")); }
public ActionResult RemoveListFile(string recId) { FileInfoBLL fileBll = new FileInfoBLL(); int res = 0; if (recId != null) { res = fileBll.DeleteFileByRecId(recId); } return(res > 0 ? Success("操作成功。") : Error("操作失败")); }