public static bool DeleteLocalPhotoFiles(int imageID, SueetiePhotoType _photoType) { var result = false; try { var fullPhotoPath = GetFilePath(imageID, false, SueetiePhotoSize.Full, _photoType); var mediumPhotoPath = GetFilePath(imageID, false, SueetiePhotoSize.Medium, _photoType); var smallPhotoPath = GetFilePath(imageID, false, SueetiePhotoSize.Small, _photoType); var originalPhotoPath = GetFilePath(imageID, false, SueetiePhotoSize.Original, _photoType); DeleteFile(fullPhotoPath); DeleteFile(mediumPhotoPath); DeleteFile(smallPhotoPath); DeleteFile(originalPhotoPath); result = true; } catch { result = false; } return(result); }
public static string GetFilePath(int photoId, bool forUrl, SueetiePhotoSize size, SueetiePhotoType _photoType) { string result = null; string filenameToken; if (size == SueetiePhotoSize.Full) { filenameToken = "Lg"; } else if (size == SueetiePhotoSize.Medium) { filenameToken = "Md"; } else if (size == SueetiePhotoSize.Small) { filenameToken = "Sm"; } else { filenameToken = "Org"; } var uri = HttpContext.Current.Request.Url; var rootUrl = uri.Scheme + Uri.SchemeDelimiter + uri.Host + ":" + uri.Port + "/"; var uploadPath = @"/images/slideshows/"; if (_photoType == SueetiePhotoType.ProductPhoto) { uploadPath = @"/images/products/"; } if (forUrl) { result = string.Format("{0}/{1}/{2}.{3}.jpg", rootUrl, uploadPath, photoId, filenameToken); } else { var context = HttpContext.Current; if (context != null) { var serverDirectory = context.Server.MapPath(uploadPath); var file = string.Format("{0}.{1}.jpg", photoId, filenameToken); result = Path.Combine(serverDirectory, file); } } return(result); }