Copied to clipboard

Flag this post as spam?

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


  • Andrew 25 posts 148 karma points
    Apr 08, 2019 @ 14:15
    Andrew
    0

    Content Service - Cannot Create Node

    Hi,

    I'm trying to use the Content Service to create a new node when a page has been published.

    I'm current creating the new node using the following code

    IContent c = contentService.Create("Test Name", Guid, "contentPage", author.Id);
    contentService.SaveAndPublish(c);
    

    However, when I hit the SaveAndPublish function I get the error:

    "An exception of type 'System.InvalidOperationException' occurred in Umbraco.Core.dll but was not handled in user code Additional information: Cannot save content with an empty name."

    I've tried setting the name different ways, and also tried setting the publishedName in case this is what it was having issues with but I've had no joy.

    Does anyone have an idea what could be causing this?

  • Corné Strijkert 80 posts 456 karma points c-trib
    Apr 08, 2019 @ 14:55
    Corné Strijkert
    100

    Hi Andrew,

    It seems that it is necessary to set the name for at least one culture. Do you have more that one cultures configured?

    Then you can try this code:

    var c = contentService.Create("Test Name", Guid, "contentPage", author.Id);
    c.SetCultureName("Test Name", "en-US");
    contentService.SaveAndPublish(c);
    
  • Andrew 25 posts 148 karma points
    Apr 08, 2019 @ 15:16
    Andrew
    0

    Brilliant, thanks Corné, that's done the job! Thanks for your help :)

Please Sign in or register to post replies

Write your reply to:

Draft