private void deleteFile(string fileUrl) { if (fileUrl.Length > 0) { var relativeFilePath = _fs.GetRelativePath(fileUrl); // delete old file if (_fs.FileExists(relativeFilePath)) { _fs.DeleteFile(relativeFilePath); } string extension = (relativeFilePath.Substring(relativeFilePath.LastIndexOf(".") + 1, relativeFilePath.Length - relativeFilePath.LastIndexOf(".") - 1)); extension = extension.ToLower(); //check for thumbnails if (",jpeg,jpg,gif,bmp,png,tiff,tif,".IndexOf("," + extension + ",") > -1) { //delete thumbnails string relativeThumbFilePath = relativeFilePath.Replace("." + extension, "_thumb"); try { if (_fs.FileExists(relativeThumbFilePath + _thumbnailext)) { _fs.DeleteFile(relativeThumbFilePath + _thumbnailext); } } catch { } if (_thumbnails != "") { string[] thumbnailSizes = _thumbnails.Split(";".ToCharArray()); foreach (string thumb in thumbnailSizes) { if (thumb != "") { string relativeExtraThumbFilePath = relativeThumbFilePath + "_" + thumb + _thumbnailext; try { if (_fs.FileExists(relativeExtraThumbFilePath)) { _fs.DeleteFile(relativeExtraThumbFilePath); } } catch { } } } } } } }
public void delete(int id, string username, string password) { Authenticate(username, password); Media m = new Media(id); if (m.HasChildren) { throw new Exception("Cannot delete Media " + id + " as it has child nodes"); } Property p = m.getProperty("umbracoFile"); if (p != null) { if (!(p.Value == System.DBNull.Value)) { var path = _fs.GetRelativePath(p.Value.ToString()); if (_fs.FileExists(path)) { _fs.DeleteFile(path, true); } } } m.delete(); }
public static void Execute(string sourceFile, string name, int cropX, int cropY, int cropWidth, int cropHeight, int sizeWidth, int sizeHeight, long quality) { if (!_fs.FileExists(sourceFile)) return; string path = string.Empty; //http or local filesystem if (sourceFile.Contains("/")) path = sourceFile.Substring(0, sourceFile.LastIndexOf('/')); else path = sourceFile.Substring(0, sourceFile.LastIndexOf('\\')); // TODO: Make configurable and move to imageInfo //if(File.Exists(String.Format(@"{0}\{1}.jpg", path, name))) return; //Do we need this check as we are always working with images that are already in a folder?? //DirectoryInfo di = new DirectoryInfo(path); //if (!di.Exists) di.Create(); using (var stream = _fs.OpenFile(sourceFile)) using (var image = Image.FromStream(stream)) using (var croppedImage = CropImage(image, new Rectangle(cropX, cropY, cropWidth, cropHeight))) using (var resizedImage = ResizeImage(croppedImage, new Size(sizeWidth, sizeHeight))) using (var b = new Bitmap(resizedImage)) { SaveJpeg(String.Format("{0}/{1}.jpg", path, name), b, quality); } }