diff --git a/src/Umbraco.Core/StringExtensions.cs b/src/Umbraco.Core/StringExtensions.cs
index 036b5b979f..02f2193e20 100644
--- a/src/Umbraco.Core/StringExtensions.cs
+++ b/src/Umbraco.Core/StringExtensions.cs
@@ -105,8 +105,8 @@ namespace Umbraco.Core
//if the resolution was success, return it, otherwise just return the path, we've detected
// it's a path but maybe it's relative and resolution has failed, etc... in which case we're just
// returning what was given to us.
- return resolvedUrlResult.Success
- ? resolvedUrlResult
+ return resolvedUrlResult.Success
+ ? resolvedUrlResult
: Attempt.Succeed(input);
}
}
@@ -128,7 +128,7 @@ namespace Umbraco.Core
}
internal static readonly Regex Whitespace = new Regex(@"\s+", RegexOptions.Compiled);
- internal static readonly string[] JsonEmpties = new [] { "[]", "{}" };
+ internal static readonly string[] JsonEmpties = new[] { "[]", "{}" };
internal static bool DetectIsEmptyJson(this string input)
{
return JsonEmpties.Contains(Whitespace.Replace(input, string.Empty));
@@ -1470,5 +1470,29 @@ namespace Umbraco.Core
byte[] hash = md5.ComputeHash(myStringBytes);
return new Guid(hash);
}
+
+
+ ///
+ /// Converts a file name to a friendly name for a content item
+ ///
+ ///
+ ///
+ public static string friendlyNameFromFilename(this string fileName)
+ {
+ // strip the file extension
+ fileName = StripFileExtension(fileName);
+
+ // underscores and dashes to spaces
+ fileName = ReplaceMany(fileName, new char[] { '_', '-' }, ' ');
+
+ // any other conversions ?
+
+ // Pascalcase (to be done last)
+ fileName = System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(fileName);
+
+
+ return fileName;
+ }
+
}
}
diff --git a/src/Umbraco.Web/Editors/MediaController.cs b/src/Umbraco.Web/Editors/MediaController.cs
index 08140f9c66..7f6c9f2580 100644
--- a/src/Umbraco.Web/Editors/MediaController.cs
+++ b/src/Umbraco.Web/Editors/MediaController.cs
@@ -534,15 +534,7 @@ namespace Umbraco.Web.Editors
if (UmbracoConfig.For.UmbracoSettings().Content.ImageFileTypes.Contains(ext))
mediaType = Constants.Conventions.MediaTypes.Image;
- //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.friendlyNameFromFilename();
var f = mediaService.CreateMedia(mediaItemName, parentId, mediaType, Security.CurrentUser.Id);