diff --git a/src/Umbraco.Core/StringExtensions.cs b/src/Umbraco.Core/StringExtensions.cs
index d2a1d97709..c6b4da96eb 100644
--- a/src/Umbraco.Core/StringExtensions.cs
+++ b/src/Umbraco.Core/StringExtensions.cs
@@ -1574,5 +1574,29 @@ namespace Umbraco.Core
guid[left] = guid[right];
guid[right] = temp;
}
+
+ ///
+ /// Converts a file name to a friendly name for a content item
+ ///
+ ///
+ ///
+ public static string ToFriendlyName(this string fileName)
+ {
+ // strip the file extension
+ fileName = fileName.StripFileExtension();
+
+ // underscores and dashes to spaces
+ fileName = fileName.ReplaceMany(new[] { '_', '-' }, ' ');
+
+ // any other conversions ?
+
+ // Pascalcase (to be done last)
+ fileName = System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(fileName);
+
+ // Replace multiple consecutive spaces with a single space
+ fileName = string.Join(" ", fileName.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries));
+
+ return fileName;
+ }
}
}
diff --git a/src/Umbraco.Web/Editors/MediaController.cs b/src/Umbraco.Web/Editors/MediaController.cs
index e22c83cbeb..59693e94a2 100644
--- a/src/Umbraco.Web/Editors/MediaController.cs
+++ b/src/Umbraco.Web/Editors/MediaController.cs
@@ -717,15 +717,7 @@ namespace Umbraco.Web.Editors
mediaType = result.FormData["contentTypeAlias"];
}
- //TODO: make the media item name "nice" since file names could be pretty ugly, we have
- // string extensions to do much of this but we'll need:
- // * Pascalcase the name (use string extensions)
- // * strip the file extension
- // * underscores to spaces
- // * probably remove 'ugly' characters - let's discuss
- // All of this logic should exist in a string extensions method and be unit tested
- // http://issues.umbraco.org/issue/U4-5572
- var mediaItemName = fileName;
+ var mediaItemName = fileName.ToFriendlyName();
var f = mediaService.CreateMedia(mediaItemName, parentId, mediaType, Security.CurrentUser.Id);