public ActionResult Download(int ID) { TAI_LIEU doc = db.TAI_LIEU.SingleOrDefault(x => x.IDTaiLieu == ID); Response.Clear(); Response.ContentType = "application/octect-stream"; Response.AppendHeader("content-disposition", "filename=" + doc.FilePath); Response.TransmitFile(Server.MapPath("~/Content/Document/") + doc.FilePath); Response.End(); return(RedirectToAction("Index")); }
public ActionResult ThemTaiLieu(TAI_LIEU model) { if (ModelState.IsValid) { var file = Request.Files["FilePath"]; if (file != null && file.ContentLength > 0) { string path = Server.MapPath("../../../Content/Document/" + file.FileName); file.SaveAs(path); } db.TAI_LIEU.Add(model); db.SaveChanges(); return(RedirectToAction("Index")); } return(View()); }