Image Draft / Publish and Deleting

Posted by Community Admin on 04-Aug-2018 16:20

Image Draft / Publish and Deleting

All Replies

Posted by Community Admin on 23-Feb-2011 00:00

In the documentation it says that savechanges process all the items marked for deletion, but I see that they are still in draft mode.
Also, when uploading an image and using .CheckOut().UploadContent(uploadedFile.InputStream, uploadedFile.GetExtension()).CheckInAndPublish().SaveChanges(); the image says it is in Draft, but the Icon has the check mark like it is published... which one is it? See the attached image.

Note that the method only marks the items for deletion, while SaveChanges() runs the transactions and processes all marked items. Having that said, you may delete multiple images, before running theSaveChanges() method

http://www.sitefinity.com/40/help/developer-manual/modules-built-in-modules-api-media-modules-images-managing-images-deleting-images.html

Posted by Community Admin on 28-Feb-2011 00:00

Hi Kristian,

Can you try to use CheckInAndPublish only.

CheckIn() - Makes the changes in the temp by copying it to the draft. The item is no longer locked and the temp is deleted.

Publish() - Publish the content item by making the item visible on the frontend

Greetings,
Ivan Dimitrov
the Telerik team

Posted by Community Admin on 28-Feb-2011 00:00

I am using CheckInAndPublish Here is my code

Upload Image

using (var sf = App.Prepare().SetTransactionName("UploadImageTransaction").WorkWith())
        try
                
                   
                    sf.Albums().GetManager().Provider.SuppressSecurityChecks = true;
 
                    sf.Album(albumToLoc.Id).CreateImage().Do(item =>
                    
                        // Upload the image with the appropriate info.
                        item.Title = imageTitle;
                        item.Description = imageDescription;
                    ).CheckOut().UploadContent(uploadedFile.InputStream, uploadedFile.GetExtension()).CheckInAndPublish().SaveChanges();
 
 
                   
                    sf.Albums().GetManager().Provider.SuppressSecurityChecks = false;
                
        catch (Exception fex)
                
                   
                    sf.Albums().GetManager().Provider.SuppressSecurityChecks = false;
                

Delete image
// Delete the image based on its Id.
            LibrariesManager libManager = LibrariesManager.GetManager();
            Telerik.Sitefinity.Libraries.Model.Image imageToDelete = libManager.GetImages()
                                        .Where(img => img.Id == imageId)
                                        .Single();
 
            libManager.Provider.SuppressSecurityChecks = true;
            libManager.DeleteImage(imageToDelete);
 
             
 
             
            libManager.SaveChanges();
            libManager.Provider.SuppressSecurityChecks = false;

Posted by Community Admin on 03-Mar-2011 00:00

Is there any update on this?

Posted by Community Admin on 14-Mar-2011 00:00

Hi Kristian,

The problem is that you are getting a Single item. This will not necessary delete the master version the item. try using the delete method without getting single item. Generraly an item will have 3 states - draft, live and master.

Regards,
Radoslav Georgiev
the Telerik team

Posted by Community Admin on 14-Mar-2011 00:00

Ok I tried a couple other ways and I haven't managed to get it to work. If I don't use Single() or SingleOrDefault() I get an error, I can't leave it blank...

I even tried using the fluent API as well and get the same result

App.WorkWith()
               .Images()
               .Where(i => i.Id == imageId)
               .Delete()
               .SaveChanges();

Posted by Community Admin on 17-Mar-2011 00:00

Hello Kristian,

Can you try this:

App.WorkWith().Image(imageId).Delete();


Best wishes,
Radoslav Georgiev
the Telerik team

Posted by Community Admin on 17-Mar-2011 00:00

This hasn't worked for me, I have opened a ticket with my attached control.

This thread is closed