I'm just going to leave this for someone else who might find it useful. This applies to those who have or know the parent node (parentNode).
To create a new node using CreateContent:
var contentService = Current.Services.ContentService;
var udi = new GuidUdi(parentNode.ContentType.ItemType.ToString(), parentNode.Key);
var newNode = contentService.CreateContent(name, udi, contentTypeAlias);
contentService.Save(newNode);
or create a new node with the Create method using the Key attribute to create a GUID:
var contentService = Current.Services.ContentService;
var parentId = new Guid(parentNode.Key.ToString());
var newNode = contentService.Create(name, parentId, contentTypeAlias);
contentService.Save(newNode);
CS0029: Cannot implicitly convert type 'System.Guid' to 'Umbraco.Core.Udi'
I are trying to auto create a Content Node as a sub node when ever a particular document type is added o the content.
Example would be a content Node (sub node) every time a new page node is created.
but I keep getting stuck with the parent node Id.
an error simalar to below comes up
CS0029: Cannot implicitly convert type 'System.Guid' to 'Umbraco.Core.Udi'
on this line of code
The error changes dependent on how or what you pass in place of "key"
according to documentation I should be able to just use elem.Id.
below is the context of the code around it.
Hi Daniel
elem.Key - is Guid, not Udi. Try this code:
Been there. But tried again. Copied your code direct. Gives this
CS1503: Argument 3: cannot convert from 'System.Guid' to 'Umbraco.Core.Udi'
Daniel, what version of Umbraco are you using?
Umbraco 8.0.2 new fresh install
Have just updated to 8.1.
Solved
I need to be using ContentService_Saved as I wouldnt have a parent Id to link the sub document to.
Using this allowed acces to the Udi
I'm just going to leave this for someone else who might find it useful. This applies to those who have or know the parent node (parentNode).
To create a new node using CreateContent:
or create a new node with the Create method using the Key attribute to create a GUID:
I hope this helps you.
is working on a reply...