Copied to clipboard

Flag this post as spam?

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


  • Euge 23 posts 130 karma points
    Jun 12, 2017 @ 10:08
    Euge
    0

    Loop through content tree and change document type

    Hi

    I need to loop through a list of nodes and change their document type to a new doc type. I need to do this programmatically. Any ideas?

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Jun 12, 2017 @ 10:41
    Alex Skrypnyk
    1

    Hi Euge

    You can change document type of content item with this code:

    var node = ApplicationContext.Services.ContentService.GetById(yourNodeId);
    var anotherContentType = ApplicationContext.Services.ContentTypeService.GetContentType(yourContentTypeId);
    
    node.ChangeContentType(anotherContentType, clearPropertyesOrNoBoolValue);
    ApplicationContext.Services.ContentService.Save(node);
    

    Thanks,

    Alex

  • Euge 23 posts 130 karma points
    Jun 12, 2017 @ 10:48
    Euge
    0

    OK thanks Alex so will this automatically map all the doc type properties to new GUIDs?

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Jun 12, 2017 @ 10:51
    Alex Skrypnyk
    1

    You are welcome, Euge, yes it changes the IContentType for the current Content object and removes PropertyTypes and Properties, which are not part of the new ContentType. Please use with caution as this remove differences between the new and old ContentType.

    Also, it's db operation so it can be long operation if you want to do it in the loop with tons of nodes.

Please Sign in or register to post replies

Write your reply to:

Draft