Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Hugo Migneron 32 posts 105 karma points
    Oct 22, 2013 @ 19:59
    Hugo Migneron
    0

    Document deprecated : Using Content instead

    I am trying to content from my umbraco site programmatically. I use

    //nodeToDelete is a umbraco.NodeFactory.Node
    Document documentToDelete = new Document(nodeToDelete.Id); 
    documentToDelete.delete(); umbraco.library.RefreshContent();

    This works fine and the content is deleted as it should. I get a warning that Document is deprecated and that I should use Content instead.

    All the examples I find on our (even the farily recent ones) of people trying to delete content use Document and not Content. Because there is no "delete" method or anything like that on Umbraco.Core.Models.Content I don't know how to do it. Actually, I don't even understand how create the object from a Node.

    What is the correct way to delete content since Document is deprecated?

    Thanks!

  • Ali Sheikh Taheri 470 posts 1648 karma points c-trib
    Oct 22, 2013 @ 20:24
    Ali Sheikh Taheri
    100

    Hi Hugo

    You should use the new API for CRUD operations.

    here is your code with new API:

    var service = ApplicationContext.Current.Services.ContentService;
    var content = service.GetById(nodeToDelete.Id);
    service.Delete(content);
    

    Tim has got a nice article of how to work with new API: http://www.nibble.be/?p=224

    Cheers

    Ali

  • Hugo Migneron 32 posts 105 karma points
    Oct 23, 2013 @ 02:04
    Hugo Migneron
    0

    Thanks a lot. I had not heard (or read about) the new API. It works for me.

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Oct 23, 2013 @ 07:11
    Jeavon Leopold
    1

    Hi Hugo,

    All the documentation for the v6 API can be found here

    Jeavon

Please Sign in or register to post replies

Write your reply to:

Draft