Copied to clipboard

Flag this post as spam?

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


  • Damien 36 posts 162 karma points
    Feb 27, 2014 @ 14:00
    Damien
    0

    v6 CreateContent method return values

    Hi,

    Does anyone know if this method can return the node id of the created content?

    I've checked the documentation here: http://our.umbraco.org/documentation/Reference/Management-v6/Services/ContentService

    Thanks

    Damien

  • Andy Butland 422 posts 2334 karma points MVP 4x hq c-trib
    Feb 27, 2014 @ 16:08
    Andy Butland
    0

    I believe these methods return an instance of the created content, so from the return object you should be able to just check it's Id property.

    Andy

  • Damien 36 posts 162 karma points
    Feb 28, 2014 @ 11:55
    Damien
    0

    Hi Andy,

    Thanks it did indeed.

        var contentService = ApplicationContext.Current.Services.ContentService;
    
        var contentNode = contentService.CreateContent(name,parentId, docTypeAlias, 0);
    
        contentNode.SetValue("productCode", productCode);
        contentNode.SetValue("currencyCode", currencyCode);
    
        //Get id of created content
        int nodeId = contentNode.Id;
    
        contentService.SaveAndPublish(contentNode);
    
  • Damien 36 posts 162 karma points
    Feb 28, 2014 @ 12:28
    Damien
    0

    Sorry I was quick to assume this worked when all i get returned is 0 for the nodeId ?

  • Damien 36 posts 162 karma points
    Feb 28, 2014 @ 12:46
    Damien
    102

    Ok, anyone else who struggles with this there is a non documented method:

    contentService.CreateContentWithIdentity

    This works a treat.

Please Sign in or register to post replies

Write your reply to:

Draft