public ActionResult Remove(string[] fileNames) { var pictureViewModel = new PictureViewModel(); // The parameter of the Remove action must be called "fileNames" if (fileNames != null) { foreach (var fullName in fileNames) { var fileName = Path.GetFileName(fullName); var physicalPath = Path.Combine("C:/ImagenPoseidon", fileName); // TODO: Verify user permissions if (System.IO.File.Exists(physicalPath)) { // The files are not actually removed in this demo System.IO.File.Delete(physicalPath); string pictureUrl = @"~/Content/Images/loading.gif"; pictureViewModel.PictureId = 1; pictureViewModel.PictureName = fileName; pictureViewModel.PictureUrl = pictureUrl; pictureViewModel.Status = false; } } } // Return an empty string to signify success return(Json(pictureViewModel, JsonRequestBehavior.AllowGet)); }
public ActionResult Save(IEnumerable <HttpPostedFileBase> files) { var pictureViewModel = new PictureViewModel(); // The Name of the Upload component is "files" if (files != null) { foreach (var file in files) { // Some browsers send file names with full path. // We are only interested in the file name. var fileName = Path.GetFileName(file.FileName); var physicalPath = Path.Combine(Server.MapPath("~/Images/"), fileName); // The files are not actually saved in this demo file.SaveAs(physicalPath); pictureViewModel.PictureId = 1; pictureViewModel.PictureName = fileName; pictureViewModel.Status = false; Session["PictureUrl"] = fileName.ToString(); HomeController.CreateFtp(); } } // Return an empty string to signify success return(Json(pictureViewModel, JsonRequestBehavior.AllowGet)); }