public ActionResult Index(CrudFileTable cft, HttpPostedFileBase fileUpload) { if (ModelState.IsValid) { var file = new FileTable(); file.Time = DateTime.Now; file.Path = path; file.UserId = User.Identity.GetUserId(); file.Name = file.Time.Year + file.Time.Month + file.Time.Day + file.Time.Hour + file.Time.Minute + file.Time.Second + "_" + Path.GetFileName(fileUpload.FileName); file.PageId = cft.FileTableUpload.PageId; if (fileUpload.ContentLength != 0) { string pathForSaving = Server.MapPath(path); if (CreateFolderIfNeeded(pathForSaving)) { try { byte[] t = new byte[fileUpload.InputStream.Length]; fileUpload.InputStream.Read(t, 0, (int)fileUpload.InputStream.Length); WriteFile(file.Path + "/" + file.Name, t); db.FileTable.Add(file); db.SaveChanges(); } catch (Exception ex) { throw ex; } } } return(RedirectToAction("index")); } return(View(cft)); }
// GET: File public ActionResult Index() { var userId = User.Identity.GetUserId(); var filetable = (from f in db.FileTable where f.UserId == userId select f).ToList(); ViewBag.PageFormatList = ppf.PageFormatList(); var model = new CrudFileTable(); model.FiletableView = filetable; return(View(model)); }