private void AddImageToProductItem(ProductItem product) { LibrariesManager librariesManager = LibrariesManager.GetManager(); if (product == null) { return; // Product does not exist } var defaultAlbum = librariesManager.GetAlbums().FirstOrDefault(a => a.Id == LibrariesModule.DefaultImagesLibraryId); Telerik.Sitefinity.Libraries.Model.Image image = UploadImage(librariesManager, "imageTitle1", "imageTitle1", "Some description", 0, Guid.Empty, defaultAlbum); product.CreateRelation(image, "ProductImage"); }
public static string GetRelatedMediaUrl(DynamicContent item, string fieldName) { var relatedItem = item.GetRelatedItems(fieldName).FirstOrDefault(); if (relatedItem != null) { var imageId = relatedItem.Id; LibrariesManager manager = LibrariesManager.GetManager(); Telerik.Sitefinity.Libraries.Model.Image image = manager.GetImage(imageId); if (image != null) { return(image.MediaUrl); } } return(null); }
private bool CreateImage(string albumTitle, string imageTitle, Stream remoteImageStream, string imageExtension, string altText) { Telerik.Sitefinity.Libraries.Model.Image image = SFLibrariesManager.GetImages().Where(i => i.Title == imageTitle).FirstOrDefault(); if (image == null) { Guid masterImageId = Guid.NewGuid(); image = SFLibrariesManager.CreateImage(masterImageId); Album album = SFLibrariesManager.GetAlbums().Where(a => a.Title == albumTitle).FirstOrDefault(); if (album != null) { image.Parent = album; image.Title = imageTitle.ToLower(); image.DateCreated = DateTime.UtcNow; image.PublicationDate = DateTime.UtcNow; image.LastModified = DateTime.UtcNow; image.UrlName = Regex.Replace(imageTitle.ToLower(), @"[^\w\-\!\$\'\(\)\=\@\d_]+", "-"); image.AlternativeText = altText; SFLibrariesManager.Upload(image, remoteImageStream, imageExtension); SFLibrariesManager.RecompileItemUrls <Telerik.Sitefinity.Libraries.Model.Image>(image); SFLibrariesManager.SaveChanges(); var bag = new Dictionary <string, string>(); bag.Add("ContentType", typeof(Telerik.Sitefinity.Libraries.Model.Image).FullName); WorkflowManager.MessageWorkflow(masterImageId, typeof(Telerik.Sitefinity.Libraries.Model.Image), null, "Publish", false, bag); } else { CreateAlbum(albumTitle); CreateImage(albumTitle, imageTitle, remoteImageStream, imageExtension, altText); } } return(true); }
public void SetIcon(Telerik.Sitefinity.Libraries.Model.Image relatedItem) { this.SetRelatedItem(RelatedItem.ICON_FIELD_NAME, relatedItem); }
public void AddMultipleImageField(Telerik.Sitefinity.Libraries.Model.Image relatedItem) { this.AddRelatedItem(FullItem.MULTIPLEIMAGEFIELD_FIELD_NAME, relatedItem); }
public void SetSingleImageField(Telerik.Sitefinity.Libraries.Model.Image relatedItem) { this.SetRelatedItem(FullItem.SINGLEIMAGEFIELD_FIELD_NAME, relatedItem); }