private void FillProperties(global::umbraco.cms.businesslogic.Content content, global::umbraco.cms.businesslogic.property.Property property) { var uploadFieldConfigNode = UmbracoConfig.For.UmbracoSettings().Content.ImageAutoFillProperties .FirstOrDefault(x => x.Alias == property.PropertyType.Alias); if (uploadFieldConfigNode != null) { var fileSystem = FileSystemProviderManager.Current.GetFileSystemProvider <MediaFileSystem>(); //Ensure that the Property has a Value before continuing if (property.Value == null) { return; } var path = fileSystem.GetRelativePath(property.Value.ToString()); if (string.IsNullOrWhiteSpace(path) == false && fileSystem.FileExists(path)) { long size; using (var fileStream = fileSystem.OpenFile(path)) { size = fileStream.Length; } var extension = fileSystem.GetExtension(path) != null ? fileSystem.GetExtension(path).Substring(1).ToLowerInvariant() : ""; var isImageType = UmbracoConfig.For.UmbracoSettings().Content.ImageFileTypes.InvariantContains(extension); var dimensions = isImageType ? GetDimensions(path, fileSystem) : null; if (isImageType) { // only add dimensions to web images content.getProperty(uploadFieldConfigNode.WidthFieldAlias).Value = dimensions.Item1.ToString(CultureInfo.InvariantCulture); content.getProperty(uploadFieldConfigNode.HeightFieldAlias).Value = dimensions.Item2.ToString(CultureInfo.InvariantCulture); } content.getProperty(uploadFieldConfigNode.LengthFieldAlias).Value = size == default(long) ? string.Empty : size.ToString(CultureInfo.InvariantCulture); content.getProperty(uploadFieldConfigNode.ExtensionFieldAlias).Value = string.IsNullOrEmpty(extension) ? string.Empty : extension; } } }
private void UpdateProperty(XmlNode uploadFieldConfigNode, global::umbraco.cms.businesslogic.Content content, string propertyAlias, object propertyValue) { XmlNode propertyNode = uploadFieldConfigNode.SelectSingleNode(propertyAlias); if (propertyNode != null && !String.IsNullOrEmpty(propertyNode.FirstChild.Value)) { if (content.GenericProperties.Any(x => x.PropertyType.Alias == propertyNode.FirstChild.Value) && content.getProperty(propertyNode.FirstChild.Value) != null) { content.getProperty(propertyNode.FirstChild.Value).Value = propertyValue; } } }