Copied to clipboard

Flag this post as spam?

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


  • Richard Hamilton 36 posts 158 karma points
    Jun 25, 2020 @ 14:42
    Richard Hamilton
    0

    Umbraco 8 move a node to a parent folder by it's parent folder key (Guid)

    Hi,

    in Umbraco 8 I want to move a node to a parent folder by it's parent folder key (Guid)

    Can I do something like this:

    _contentService.Move(orderNode, new Guid(archiveParentId));

    It says it needs the integer Id but thought we were moving away from them?

    Many thanks

  • Marc Goodson 2157 posts 14434 karma points MVP 9x c-trib
    Jun 27, 2020 @ 11:49
    Marc Goodson
    100

    Hi Richard

    It looks like the ContentService doesn't have a signature for move that takes the parent GUID 'yet'

    https://github.com/umbraco/Umbraco-CMS/blob/d65041c2503fc85ac4619a4abcd703dcc20f067d/src/Umbraco.Core/Services/Implement/ContentService.cs#L1923

    (you can see 'Create' has been updated in this file to have both int Id, and Guid signatures).

    The 'GetById' method has both signatures:

    https://github.com/umbraco/Umbraco-CMS/blob/d65041c2503fc85ac4619a4abcd703dcc20f067d/src/Umbraco.Core/Services/Implement/ContentService.cs#L377

    So if you ONLY have access to the parent GUID in your custom method, you could first retrieve the parent as an IContent item and pass the integer Id into the move signature.

    IContent archiveParent = _ContentService.GetById(archiveParentGuid);
    _contentService.Move(orderNode, archiveParent.Id);
    

    but, as the Move method will then retrieve the IContent object again for the Parent by it's integer Id, it would be much better to have signatures taking in the Guid and/or an IContent item for the Parent when performing this Move...

    regards

    Marc

  • Richard Hamilton 36 posts 158 karma points
    Jun 28, 2020 @ 14:57
    Richard Hamilton
    0

    Thanks Marc

    Thats what I went with for now.

    I guess I could add this as an application variable as the parent folders should not be deleted.

  • 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