Image Draft / Publish and Deleting
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
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
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 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
;
Is there any update on this?
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
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();
Hello Kristian,
Can you try this:
App.WorkWith().Image(imageId).Delete();
This hasn't worked for me, I have opened a ticket with my attached control.