Copied to clipboard

Flag this post as spam?

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


  • Rabea 34 posts 186 karma points
    Apr 26, 2019 @ 05:26
    Rabea
    0

    Cannot save content with an empty name

    I have a simple method in surface controller after form submit, which has a file upload and name and email, but after saveandpulish, i get this error that "Cannot save content with an empty name"

    content.SetValue("entry", model.FileUpload);
    
            contentService.SaveAndPublish(content);
    

    Any help regarding what am i missing? this worked fine in umbraco 7 for me

  • Corné Strijkert 80 posts 456 karma points c-trib
    Apr 26, 2019 @ 08:23
    Corné Strijkert
    6

    You must provide a name for the content object you're trying to save. In Umbraco 8 you have multiple ways to do that:

    contentService.Create("Name here", -1, "contentTypeAlias");
    

    When you have multiple cultures configured, you can use:

    content.SetCultureName("Name here", "en-US");
    
  • Rabea 34 posts 186 karma points
    Apr 26, 2019 @ 09:31
    Rabea
    0

    Thanks Corné for response, my current code looks like this:

    IContentService contentService = Services.ContentService;
    var content = contentService.CreateContent("samplename", udi, sample.ModelTypeAlias);
    content.SetValue("entry", model.FileUpload);
    
     contentService.SaveAndPublish(content);
    

    If you can please correct me in what i am missing here

  • Corné Strijkert 80 posts 456 karma points c-trib
    Apr 26, 2019 @ 09:36
    Corné Strijkert
    105

    I assume you've multiple languages configured?

    Then I think you should use the SetCultureName() extension on the IContent object for at least the required languages.

  • Rabea 34 posts 186 karma points
    Apr 26, 2019 @ 09:42
    Rabea
    1

    Yes i have danish and english configured and i am trying to create this node in english language

  • Morten Hartvig 5 posts 78 karma points
    Apr 26, 2019 @ 12:55
    Morten Hartvig
    2

    Hi Rabea,

    The methods in V8's IContentService allow you to specify a culture. :) Try the following:

    IContentService contentService = Services.ContentService;
    var content = contentService.CreateContent("samplename", udi, sample.ModelTypeAlias);
    content.SetValue("field", "value", "en-US");
    
    contentService.SaveAndPublish(content, "en-US");
    
  • Rabea 34 posts 186 karma points
    Apr 27, 2019 @ 07:33
    Rabea
    0

    This worked, thanks a lot

  • Ault Nathanielsz 87 posts 407 karma points c-trib
    Sep 20, 2019 @ 15:08
    Ault Nathanielsz
    0

    This was helpful. Where can one find documentation for V8 Services.ContentService? (I have been looking, but possibly not carefully enough. Everything I turn up is pre-8)

Please Sign in or register to post replies

Write your reply to:

Draft