diff --git a/src/umbraco.cms/businesslogic/media/UmbracoMediaFactory.cs b/src/umbraco.cms/businesslogic/media/UmbracoMediaFactory.cs index 52ad7beb84..8f2d841fa5 100644 --- a/src/umbraco.cms/businesslogic/media/UmbracoMediaFactory.cs +++ b/src/umbraco.cms/businesslogic/media/UmbracoMediaFactory.cs @@ -85,15 +85,20 @@ namespace umbraco.cms.businesslogic.media if (childMedia.ContentType.Alias == MediaTypeAlias) { var prop = childMedia.getProperty("umbracoFile"); - if (prop != null) + if (prop != null && prop.Value != null) { - var destFilePath = FileSystem.GetRelativePath(prop.Id, fileName); - var destFileUrl = FileSystem.GetUrl(destFilePath); - - if (prop.Value.ToString() == destFileUrl) + int subfolderId; + var subfolder = prop.Value.ToString().Replace(FileSystem.GetUrl("/"), "").Split('/')[0]; + if (int.TryParse(subfolder, out subfolderId)) { - existingMedia = childMedia; - return true; + var destFilePath = FileSystem.GetRelativePath(subfolderId, fileName); + var destFileUrl = FileSystem.GetUrl(destFilePath); + + if (prop.Value.ToString() == destFileUrl) + { + existingMedia = childMedia; + return true; + } } } }