create a live image item with a specific id

Posted by Community Admin on 04-Aug-2018 15:05

create a live image item with a specific id

All Replies

Posted by Community Admin on 03-Jan-2013 00:00

Hi guys,

i have a little problem. Is it possible to create a image with a specific master id and a specific live id.
Here is my current code. This code works, but gives me a image with a specific master id and auto generated live id.

foreach (dsImageGalery.ImageRow ImageItem in dtImages.Where(row => row.IDAlbum == albumId).ToList())
                
                    Guid masterImageId = ImageItem.ID;
                    Guid LiveImageId = ImageItem.IDMaster;
                    LibrariesManager ImagelibrariesManager = LibrariesManager.GetManager();
                    Telerik.Sitefinity.Libraries.Model.Image image = ImagelibrariesManager.GetImages().Where(i => i.Id == LiveImageId).FirstOrDefault();
                    if (image == null)
                    
                        image = ImagelibrariesManager.CreateImage(LiveImageId);
                        Album Imagealbum = ImagelibrariesManager.GetAlbums().Where(i => i.Id == albumId).SingleOrDefault();
                        image.Parent = Imagealbum;
                        image.Title = ImageItem.Title;
                        image.DateCreated = ImageItem.DateCreated;
                        image.PublicationDate = DateTime.UtcNow;
                        image.LastModified = ImageItem.LastModified;
                        image.UrlName = ImageItem.URLName;
                        image.OriginalContentId = masterImageId;
                        Stream FileStream = new MemoryStream(ImageItem.FileContent);
                        ImagelibrariesManager.Upload((MediaContent)image, (Stream)FileStream, GetDefaultExtension(ImageItem.FileType));
                        ImagelibrariesManager.SaveChanges();
                        var bag = new Dictionary<string, string>();
                        bag.Add("ContentType", typeof(Telerik.Sitefinity.Libraries.Model.Image).FullName);
                        WorkflowManager.MessageWorkflow(LiveImageId, typeof(Telerik.Sitefinity.Libraries.Model.Image), null, "Publish", false, bag);
                    
                

Kind Regards
eb-1988

Posted by Community Admin on 09-Jan-2013 00:00

Hi Emanuel,

 Thanks for using Sitefinity.

Is there a specific reason why you want to set the live ID of an image? Even when you query images you query them by the master ID and their workflow status.

For example, this gets the live copy of the image with the given masterID


private Image GetImageFluentAPI(Guid masterImageId)
    return App.WorkWith().Image(masterImageId).GetLive().Get();

You can see the documentation for creating, query, modifying, and deleting images here. Regards,
Patrick Dunn
the Telerik team
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 09-Jan-2013 00:00

Hi Patrick,

thank you for your answer.

Yes i have a specific reason. I've created a process, that Export (and later Import) all Images and documents with their libraries and also their original master and live id.

The Problem is the following: I have many Projects with the same source of Events and news. In the events-/news-Content i have also Images to Display. To solve this chaos, i will centralize all Images and documents in one sf Project, but sf saves in the Content block the live id of an media element. This is the reason for this.

I hope you can understand my Problem :)

Kind Regards

eb-1988

 

Posted by Community Admin on 10-Jan-2013 00:00

Hi Emanuel,

Thank you for getting back to us.

All queries for images through the API are done with the masterID and workflow status if you want to specify only published items, for example. 

I think I understand what you're trying to do, though. You want to take images from a number of SF projects and link them into a single SF project programatically keeping the liveID the same to be referenced by the sfref so they don't break.

As of right now there is no way to specify the contentId (or live ID) of an image through the API while being published. These are generated randomly by the Workflow manager and replicated throughout the required locations in the database.

I hope that the information above was useful.

Greetings,
Patrick Dunn
the Telerik team
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 10-Jan-2013 00:00

Hi Patrick,

thank you for your answer.

Today i've executed the import/export process. All sitefinity image controls losses their source as excepted, but all images in my generic control don't break. 

Kind Regards

Emanuel

This thread is closed