public ActionResult DelFile(StoredFile file) { var db = new FileContext(); var fl = db.StoredFiles.Single(f => f.Id == file.Id); db.StoredFiles.Remove(fl); db.SaveChanges(); return RedirectToAction("AllFiles"); }
public ActionResult Upload(HttpPostedFileBase file) { if (file != null) { string fileName = System.IO.Path.GetFileName(file.FileName); string extention = Path.GetExtension(file.FileName); List<string> extentions = new List<string>() { ".txt", ".png", ".jpg", ".pdf", ".zip" }; if (extentions.Contains(extention)) { string path = System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath + "\\Image\\Files\\" + User.Identity.Name.ToString(); Directory.CreateDirectory(path); file.SaveAs(Server.MapPath("~/Image/Files/" + User.Identity.Name.ToString() + "/" + fileName)); var db = new FileContext(); var role = db.StoredFiles.Where(f => f.Name == fileName).FirstOrDefault(); if (role != null) { Session["Lastfilename"] = ""; return View(); } Session["Lastfilename"] = "Last uploaded file"+fileName; db.StoredFiles.Add(new StoredFile() { Name = fileName, UserName = User.Identity.Name.ToString() }); db.SaveChanges(); } else { Session["Lastfilename"] = "Extetion is not supported. You can upload only: .txt, .png, .jpg, .pdf, .zip"; } } return View(); }