diff --git a/src/Orchard.Web/Modules/Orchard.MediaLibrary/Controllers/ClientStorageController.cs b/src/Orchard.Web/Modules/Orchard.MediaLibrary/Controllers/ClientStorageController.cs index b5f75fdb9..00d7aacf6 100644 --- a/src/Orchard.Web/Modules/Orchard.MediaLibrary/Controllers/ClientStorageController.cs +++ b/src/Orchard.Web/Modules/Orchard.MediaLibrary/Controllers/ClientStorageController.cs @@ -178,9 +178,15 @@ namespace Orchard.MediaLibrary.Controllers { .Where(x => x.FolderPath == replaceMedia.FolderPath && x.FileName == replaceMedia.FileName) .Count(); if (mediaItemsUsingTheFile == 1) { // if the file is referenced only by the deleted media content, the file too can be removed. - _mediaLibraryService.DeleteFile(replaceMedia.FolderPath, replaceMedia.FileName); - } - else { + try { + _mediaLibraryService.DeleteFile(replaceMedia.FolderPath, replaceMedia.FileName); + } catch (ArgumentException) { // File not found by FileSystemStorageProvider is thrown as ArgumentException. + statuses.Add(new { + error = T("Error when deleting file to replace: file {0} does not exist in folder {1}. Media has been updated anyway.", replaceMedia.FileName, replaceMedia.FolderPath).Text, + progress = 1.0 + }); + } + } else { // it changes the media file name replaceMedia.FileName = filename; }