public ActionResult AnnullaUploadImmagine(string nome) { try { string antiForgeryToken = Request.Form.Get("__TokenUploadFoto"); if (!string.IsNullOrWhiteSpace(antiForgeryToken) && !antiForgeryToken.ToLower().Equals("undefined")) { string pathBase = Path.Combine(Server.MapPath("~/Temp/Images/"), Session.SessionID, antiForgeryToken); string pathImgOriginale = Path.Combine(pathBase, "Original", nome); string pathImgMedia = Path.Combine(pathBase, "Normal", nome); string pathImgPiccola = Path.Combine(pathBase, "Little", nome); System.IO.File.Delete(pathImgOriginale); System.IO.File.Delete(pathImgMedia); System.IO.File.Delete(pathImgPiccola); //return Json(new { Success = true }); string[] listaFotoUpload = Directory.GetFiles(Path.Combine(pathBase, "Little")); PubblicaListaFotoViewModel model = new PubblicaListaFotoViewModel(); model.TokenUploadFoto = antiForgeryToken; if (listaFotoUpload != null && listaFotoUpload.Length > 0) { model.Foto = listaFotoUpload.Select(m => new FileInfo(m).Name).ToList(); } return(PartialView("PartialPages/_GalleriaFotoAnnuncio", model)); } } catch (Exception ex) { //Elmah.ErrorSignal.FromCurrentContext().Raise(ex); LoggatoreModel.Errore(ex); } //return Json(new { Success = false, responseText = Language.ErrorFormatFile }); Response.StatusCode = (int)System.Net.HttpStatusCode.BadRequest; return(null); }
public JsonResult UploadImmagine(HttpPostedFileBase file) { if (file != null && Utility.CheckFormatoFile(file)) { string antiForgeryToken = Request.Form.Get("__TokenUploadFoto"); if (!string.IsNullOrWhiteSpace(antiForgeryToken) && !antiForgeryToken.ToLower().Equals("undefined")) { FileUploadifive foto = UploadImmagine("/Temp/Images/" + Session.SessionID + "/" + antiForgeryToken, file); foto.Id = foto.Nome; string pathBase = Path.Combine(Server.MapPath("~/Temp/Images/"), Session.SessionID, antiForgeryToken, "Little"); string[] listaFotoUpload = Directory.GetFiles(pathBase); PubblicaListaFotoViewModel model = new PubblicaListaFotoViewModel(); model.TokenUploadFoto = antiForgeryToken; if (listaFotoUpload != null && listaFotoUpload.Length > 0) { model.Foto = listaFotoUpload.Select(m => new FileInfo(m).Name).ToList(); } string htmlGalleriaFotoAnnuncio = RenderRazorViewToString("PartialPages/_GalleriaFotoAnnuncio", model); return(Json(new { Success = true, responseText = htmlGalleriaFotoAnnuncio, Foto = foto })); } //return Json(new { Success = true, responseText = foto }); } //messaggio di errore return(Json(new { Success = false, responseText = Language.ErrorFormatFile })); }