public ActionResult filesProj(string id) { int idI = Convert.ToInt32(id); var workroom = db.tbProjWorkrooms.Find(idI); var filePath = Server.MapPath("~/App_Data/WorkroomFiles/" + id + "/"); DirectoryInfo di = new DirectoryInfo(filePath); FileModel wrFiles = new FileModel(); wrFiles.projFiles = new List <tbProjWorkroomFile>(); try { foreach (FileInfo file in di.GetFiles()) { tbProjWorkroomFile f = new tbProjWorkroomFile(); f.filename = file.Name; f.size = file.Length.ToString(); f.date = file.CreationTime.ToString(); try { f.uploadedBy = workroom.tbMessages.Where(wr => wr.attachment.Equals(f.filename)).FirstOrDefault().mfrom; } catch { f.uploadedBy = workroom.tbProjWorkroomFiles.Where(wrFile => wrFile.filename.Equals(f.filename)).FirstOrDefault().uploadedBy; } wrFiles.projFiles.Add(f); } TempData["page"] = "filesProj"; ViewBag.wroomID = id; return(View(wrFiles)); } catch { TempData["page"] = "filesProj"; ViewBag.wroomID = id; return(View(wrFiles)); } }
public ActionResult filesProj(string wr, string filename) { var temp = Request["wr"].ToString(); int id = Convert.ToInt32(wr); var workroom = db.tbProjWorkrooms.Find(id); var filePath = Server.MapPath("~/App_Data/WorkroomFiles/" + workroom.wrID + "/"); tbProjWorkroomFile model = new tbProjWorkroomFile(); List <SerializeFileModel> filesAdded = new List <SerializeFileModel>(); try { if (Request.Files.Count > 0) { foreach (string file in Request.Files) { var fileContent = Request.Files[file]; if (fileContent != null && fileContent.ContentLength > 0) { SerializeFileModel sFile = new SerializeFileModel(); bool IsExists = System.IO.Directory.Exists(Server.MapPath("~/App_Data/WorkroomFiles/" + id)); if (!IsExists) { System.IO.Directory.CreateDirectory(Server.MapPath("~/App_Data/WorkroomFiles/" + id)); } var fileSavePath = Path.Combine(Server.MapPath("~/App_Data/WorkroomFiles/" + id), fileContent.FileName); fileContent.SaveAs(fileSavePath); model.wrID = id; model.filename = fileContent.FileName; model.size = Convert.ToString(fileContent.ContentLength); model.date = DateTime.Today.ToShortDateString(); model.uploadedBy = workroom.tbAwardedProj.tbProject.tbPM.tbUser.firstName + " " + workroom.tbAwardedProj.tbProject.tbPM.tbUser.lastName; db.tbProjWorkroomFiles.Add(model); sFile.filename = model.filename; sFile.size = model.size; sFile.date = model.date; sFile.uploadedBy = model.uploadedBy; filesAdded.Add(sFile); db.SaveChanges(); } } } else { return(Json(false)); } TempData["page"] = "filesProj"; ViewBag.wrID = workroom.wrID; return(Json(new { obj = filesAdded }, JsonRequestBehavior.AllowGet)); } catch { TempData["page"] = "filesProj"; ViewBag.wrID = workroom.wrID; return(Json(false)); } }