Copied to clipboard

Flag this post as spam?

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


  • John Seto 37 posts 98 karma points
    Sep 06, 2016 @ 15:51
    John Seto
    0

    Setting on a root node programatically

    Anyone know what the U7 equivalent to the following is:

    umbraco.cms.businesslogic.web.Domain.MakeNew("http://domain.com", nodeId, languageId);
    

    TIA

  • Damiaan 442 posts 1302 karma points MVP 6x c-trib
    Sep 06, 2016 @ 20:54
    Damiaan
    1

    First create the Content object, you could use the createContent Helper on the ContentService. Then save the content object using the Save (or SaveAndPublishWithStatus) from the ContentService.

    var newNode = ApplicationContext.Services.ContentService.CreateContent(name, parentId, contentTypeAlias);
    ApplicationContext.Services.ContentService.Save(newNode);
    

    Hope this helps.
    Kind regards

  • Alex Skrypnyk 6175 posts 24186 karma points MVP 8x admin c-trib
    Sep 06, 2016 @ 21:37
    Alex Skrypnyk
    0

    Hi,

    Thanks Damiaan for example!

    One small thing - if you want to create root node, parentId param should be -1.

    Thanks,

    Alex

  • sandeep 12 posts 112 karma points
    Sep 07, 2016 @ 05:40
    sandeep
    0

    Hey Alex, Yes if you want to create root node then parentId should be -1 .

  • John Seto 37 posts 98 karma points
    Sep 07, 2016 @ 06:38
    John Seto
    0

    Opps I didn't realise my post was to create content.

    What was I meant to ask is how do I programmatically add a domain to a root node. I have 34 websites where I need to add a new hostname. I thought the above code did this pre-U7

  • Damiaan 442 posts 1302 karma points MVP 6x c-trib
    Sep 07, 2016 @ 08:09
    Damiaan
    2

    It's my mistake! You asked for the domain indeed!

    You need to use the ApplicationContext.Services.DomainService. To create a new it's pretty easy:

    var succes = ApplicationContext.Services.DomainService.Save(
        new UmbracoDomain("mydomainname ") {
            LanguageId = languageId, 
            RootContentId = nodeid
        });
    

    Hope this helps.

Please Sign in or register to post replies

Write your reply to:

Draft