Copied to clipboard

Flag this post as spam?

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


  • Jeffrey Schoemaker 408 posts 2138 karma points MVP 8x c-trib
    Mar 20, 2012 @ 15:08
    Jeffrey Schoemaker
    0

    Deleting nodes programmatically

    Hi all,

    I'm deleting a node in my codefile (Umbraco 4.7.1) with the following code

    Dim documentNode As New Document(Node.Id)
    documentNode.delete(True)

    If I after this point execute the code

    New Document(Node.Id); -- throws an exception - No Node exists with id 'xxx'

    This is what I expected because I deleted the node, but if I use

    New umbraco.NodeFactory.Node(Node.Id); -- returns the node (that I just deleted)

    This is not what I hoped for. Do I have to update the cache in anyway? I only know the statement

    umbraco.library.UpdateDocumentCache(Node.Id) 

    to update the cache, but this node.id does not exist any longer.

    I hope someone has an answer,


    Jeffrey

     

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Mar 20, 2012 @ 15:13
    Tom Fulton
    0

    Hi Jeffrey,

    Yes, you'll need to update the cache after you delete the document.

    You can store the node's ID in a variable before you delete it, then use that variable when calling UpdateDocumentCache().  If that doesn't work you can try using the node's parent ID, ex:

    int parentId = documentNode.ParentId;
    documentNode.delete(True);
    umbraco.library.UpdateDocumentCache(parentId);

    HTH,
    Tom

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Mar 20, 2012 @ 15:15
    Tom Fulton
    1

    You might also need to add a call to umbraco.library.RefreshContent() if the above doesn't do the trick.

  • Jeffrey Schoemaker 408 posts 2138 karma points MVP 8x c-trib
    Mar 21, 2012 @ 12:08
    Jeffrey Schoemaker
    0

    Hi Tom,

    thanks for your replies. The umbraco.library.RefreshContent() seems to be necessary and now it works

    Thanks a lot!

    Jeffrey

Please Sign in or register to post replies

Write your reply to:

Draft