Copied to clipboard

Flag this post as spam?

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


  • Erma Isabel 20 posts 91 karma points
    Oct 23, 2013 @ 14:25
    Erma Isabel
    0

    Create Child node using C#

    Hi all,

    In my project, i need to create chidnodes dynamically,

    public class PresentationController : UmbracoApiController
    {
        public string GetPresentation(int umbracoNodeId)
        {
            var franchise = Umbraco.TypedContent(umbracoNodeId);
    
            if (franchise != null)
            {
                var comments = franchise.Children.Where(x => x.DocumentTypeAlias == "Presentation");
                if (comments.Any())
                {
                    foreach (var comment in comments)
                    {
                        var region = comment.GetProperty("title").Value.ToString();
    
                    }
                }
            }
            return "success";
        }
    

    Using above code i can get parent node and available children. How can i create a new child?

    Umbraco version 6.1.6

    Please help, Thanks

  • Ali Sheikh Taheri 470 posts 1648 karma points c-trib
    Oct 23, 2013 @ 14:41
    Ali Sheikh Taheri
    0

    Hi Erma

    hope this post help you: (link here)

    Cheers

    Ali

  • Charles Afford 1163 posts 1709 karma points
    Oct 23, 2013 @ 21:12
  • Erma Isabel 20 posts 91 karma points
    Oct 25, 2013 @ 06:26
    Erma Isabel
    0

    Hi again,

    Thanks all for responses.

    @Charlie, Very good article. It helped.

    I got it working using following code,

             // Get the Umbraco Content Service
             var contentService = Services.ContentService;
             var product = contentService.CreateContent(
            "my new presentation", // the name of the product
            1055, // the parent id should be the id of the group node 
            "Presentation", // the alias of the product Document Type
            0);
    
            // We need to update properties (product id, original name and the price)
            product.SetValue("title", "My new presentation");
    
    
            // finally we need to save and publish it (which also saves the product!) - that's done via the Content Service
            contentService.SaveAndPublish(product);
    

    Hope this might help someone

Please Sign in or register to post replies

Write your reply to:

Draft