How to call CreateContent given an IContent node which has no udi
I am trying to convert some code from v7 to v8.
In the content saving event I want to create a child node onto the content that is being saved so:
IContent parent; // This is being saved.
IContent newContent = contentService.CreateContent(rule.NodeName, parent.Id, rule.DocTypeAliasToCreate);
The trouble is IContent ony has Id which is an int - I need a Udi and have no idea how to convert it to a Udi. The v7 of umbraco would accept a node id but not any more. How do I get the Udi for a IContent.Id ? IContent has a guid key but equally i have no idea how to get from that to a Udi? Thanks.
public static class ContentServiceExtensions
{
/
public static IContent CreateContent(this IContentService contentService, string name, Udi parentId, string contentTypeAlias, int userId = -1);
Thanks for the reply - but it does not work per my earlier post. I have pasted in the definition of CreateContent and you will see the [arentId parameter is a Udi - not an int. This is taken from Assembly Umbraco.Core, version 8.0.0.0.
How to call CreateContent given an IContent node which has no udi
I am trying to convert some code from v7 to v8. In the content saving event I want to create a child node onto the content that is being saved so:
The trouble is IContent ony has Id which is an int - I need a Udi and have no idea how to convert it to a Udi. The v7 of umbraco would accept a node id but not any more. How do I get the Udi for a IContent.Id ? IContent has a guid key but equally i have no idea how to get from that to a Udi? Thanks.
Hi John,
parent.Id int works fine in Umbraco 8.
So, this line will work perfectly for you. IContent newContent = contentService.CreateContent(rule.NodeName, parent.Id, rule.DocTypeAliasToCreate);
Please try and let us know if you have any issues.
Regards,
Shaishav
{
Thanks for the reply - but it does not work per my earlier post. I have pasted in the definition of CreateContent and you will see the [arentId parameter is a Udi - not an int. This is taken from Assembly Umbraco.Core, version 8.0.0.0.
Hi Shaishav,
You forced me to look again. We both mentioned the wrong method CreateContent. There is indeed a CreateAndSave method that takes an int parentId
I can work with that! Thanks.
is working on a reply...