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);
}
}
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);
}
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.
Isn't this the way that it always works. As soon as you post, you find the answer.
}
Jeff see my answer on this post:
https://our.umbraco.com/forum/using-umbraco-and-getting-started/100643-how-to-get-to-another-view-with-a-link-and-MVC
is working on a reply...