Copied to clipboard

Flag this post as spam?

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


  • Jeff Wright 2 posts 43 karma points
    Jan 31, 2020 @ 02:34
    Jeff Wright
    0

    Generating New Page Dynamically

    I have been looking for this answer for days. I am assuming that I am not a very good Googler...

    I cannot find any good examples on how to dynamically generate Umbraco Content. My basic issue is, I have 150 contacts that I want to import into the site.

    With this said, can someone please point me in the right direction on how to create just one page of dynamic content?

    In my scenario, I have a main page named "members-profile-list". Under the "members-profile-list', I need to dynamically generate a new member based on the "member-profile" template.

    I realize that the code below does not work at all, and that some of you will get a good chuckle out of it, but that is all I have. I don't know where else to go.

    using System.Web.Mvc;
    using Umbraco.Core.Models;
    using Umbraco.Core.Services;
    
    
    public class ContentServiceExampleController
    {
        private readonly IContentService _contentService;
    
        public ContentServiceExampleController(IContentService contentService)
        {
            _contentService = contentService;
        }
    
        public void CreateNewMember()
        {
    
            IContentTypeService _contentTypeService;
            _contentTypeService.Get(alias: "member-profile");
    
            var content = new Content("MembersName", members-profile-list.ID, _contentTypeService, "en-US");
    
            // Now fill in the rest of the information
            content.SetValue("firstName", "Walker");
            content.SetValue("lastName", "Ranger");
            content.SetValue("address", "123 Any Street");
    
            // Save and publish the page
            var result = _contentService.SaveAndPublish(content);
        }
    }
    
  • Jeff Wright 2 posts 43 karma points
    Jan 31, 2020 @ 15:36
    Jeff Wright
    100

    Isn't this the way that it always works. As soon as you post, you find the answer.

    using System;
    
    using Umbraco.Core;
    
    using Umbraco.Core.Services;
    
    public class ContentServiceExampleController : Umbraco.Web.Mvc.SurfaceController
    {
    
    public void CreateNewMember()
    {
        IContentService contentService = Services.ContentService;
        // ID = 1555 Page Type:Profile List parent Alias =profileList
        var parent = contentService.GetById(new Guid("1b51e4d5-b494-43eb-adb0-a8f7ad081641"));
        //var content = contentService.CreateContent("sample", parent.GetUdi(), "profileList");
        var content = contentService.CreateContent("sample", parent.GetUdi(), "profile");
        content.SetValue("firstName", "WALKER");
        content.SetValue("lastName", "RANGER");
        content.SetValue("address", "123 Any Street");
    
    
        contentService.SaveAndPublish(content);
    }
    

    }

  • Graham Davis 110 posts 376 karma points
    Jan 31, 2020 @ 18:21
Please Sign in or register to post replies

Write your reply to:

Draft