Copied to clipboard

Flag this post as spam?

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


  • David Armitage 414 posts 1655 karma points
    May 02, 2018 @ 13:20
    David Armitage
    0

    Copying & Publishing Nodes Programmatically

    Hi Guys,

    I couldn't find many helpful posts on this so I thought I would open a question.

    How do you....

    1. Copy a node and all its children programmatically

    2. Then publish this node and all its children programmatically

    Thanks in advanced

    Kind Regards

    David

  • Marthijn Kip 9 posts 96 karma points
    May 02, 2018 @ 13:24
  • David Armitage 414 posts 1655 karma points
    May 02, 2018 @ 13:37
    David Armitage
    0

    Thanks.

    I got the copy down. Its was the .PublishWithChildren method I was looking for.

    Thanks for pointing me in the right direction.

    I will give this a try and re-post the full code.

  • David Armitage 414 posts 1655 karma points
    May 02, 2018 @ 13:48
    David Armitage
    101

    Hi Guys,

    So here is the filly copy to copy and publish including children.

     var contentService = ApplicationContext.Current.Services.ContentService;
     var documentToCopy = contentService.GetById(1592);
     var newDoc = contentService.Copy(documentToCopy, 1558, false, 0);
     contentService.PublishWithChildrenWithStatus(newDoc, 0, true);
    

    If you want to copy children it's important that you set the following.

    (newDoc, 0, true); - include unpublished

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies