/// <summary> /// Add the image to Sitecore /// </summary> /// <param name="percolatePost"></param> /// <returns></returns> public MediaItem CreateMedia(PercolatePost percolatePost) { //Create the options Sitecore.Resources.Media.MediaCreatorOptions options = new Sitecore.Resources.Media.MediaCreatorOptions(); options.FileBased = false; options.IncludeExtensionInItemName = false; options.KeepExisting = false; options.Versioned = false; options.Destination = PercolateConstants.Paths.MediaPath + percolatePost.Media.Id; options.Database = Sitecore.Configuration.Factory.GetDatabase(Settings.PercolateSettings.MasterDBName); //read the image from percolate var webClient = new WebClient(); byte[] imageBytes = webClient.DownloadData(percolatePost.Media.Src); MemoryStream stream = new MemoryStream(); stream.Write(imageBytes, 0, imageBytes.Length); //create the image Sitecore.Resources.Media.MediaCreator creator = new Sitecore.Resources.Media.MediaCreator(); MediaItem mediaItem = creator.CreateFromStream(stream, string.Format("{0}.{1}", percolatePost.Media.Id, percolatePost.Media.Format), options); return mediaItem; }
public static string GetFieldMapping(string fieldName, PercolatePost post) { string perculateFieldName = GetSettingsValue(fieldName); if (!string.IsNullOrEmpty(perculateFieldName)) { string perculatefieldValue = GetPostPropValue(post, perculateFieldName).ToString(); return perculatefieldValue; } return string.Empty; }