Copied to clipboard

Flag this post as spam?

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


  • Tom 18 posts 89 karma points
    Jul 11, 2016 @ 01:06
    Tom
    0

    Creating Nodes and items programatically with data from website entered by user

    Hi, I need a new node and subnode to be created programatically in Umbraco

    Scenario: Website user(not umbraco user) will input some details through a webpage in our site. I need to create a node/childnodes and new items under these nodes using the data from the webpage.

    How can I do This?

    Thanks in advance

  • Marcio Goularte 374 posts 1346 karma points
    Jul 11, 2016 @ 03:09
  • David Armitage 505 posts 2073 karma points
    Jul 11, 2016 @ 04:28
    David Armitage
    0

    Hi,

    I just typed you up a very simply insert. I am sure you can adapt this for your needs!.

    public static int InsertExample(int parentNodeId)
    {
        var contentService = ApplicationContext.Current.Services.ContentService;
        var name = "Enter name of the node here"
        var data = contentService.CreateContent(name, parentNodeId, "Enter document type alias here", 0);
    
        //set the properties of the doument type here. Use the property alias
        //for example purposes I just assumed my document type has firstname, lastname, phone
    
        data.SetValue("firstName", "Peter");
        data.SetValue("lastName", "Pan");
        data.SetValue("phone", "0123456789");
    
        // save and publish
        contentService.SaveAndPublishWithStatus(data);
        return data.Id;
    }
    

    hope this helps.

    Kind Regards

    David

Please Sign in or register to post replies

Write your reply to:

Draft