public static string SaveImageUpload(this HttpPostedFileBase postedImage, IProvideServerMapPath serverMapPathProvider, string uploadDir) { var imagePath = Path.Combine(serverMapPathProvider.MapPath(uploadDir), postedImage.FileName); var imageUrl = Path.Combine(uploadDir + "/", postedImage.FileName); postedImage.SaveAs(imagePath); return(imageUrl); }
public static void DeleteImage(this Image imageFile, IProvideServerMapPath serverMapPathProvider, string uploadDir) { var fileName = imageFile.ImageUrl.Substring(imageFile.ImageUrl.LastIndexOf("/", System.StringComparison.Ordinal)); var imagePath = Path.Combine(serverMapPathProvider.MapPath(uploadDir), Path.GetFileName(fileName.Replace("/", "\\"))); if (File.Exists(imagePath)) { File.Delete(imagePath); } }
public static void DeleteImage(this Image imageFile, IProvideServerMapPath serverMapPathProvider, string uploadDir, string imageUrl) { // TODO: Add file name property to image so this parse is not necessary var fileName = imageUrl.Substring(imageUrl.LastIndexOf("/", System.StringComparison.Ordinal)); // BUG: image path is not being set correctly, so image is not being deleted var imagePath = Path.Combine(serverMapPathProvider.MapPath(uploadDir), fileName); if (File.Exists(imagePath)) { File.Delete(imagePath); } }