Copied to clipboard

Flag this post as spam?

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


  • Chris Lord 58 posts 211 karma points
    Aug 20, 2015 @ 19:03
    Chris Lord
    0

    Content Service - Publish

    I am using the content service to create some content, which I want to publish instantly;

    var cs = Services.ContentService; var c = cs.CreateContent("New Page", 1102, "alias");

    I then set some values;

    c.SetValue("property", "value");

    I then want to publish;

    cs.SaveAndPublishWithStatus(c); or cs.Publish(c);

    Neither actually publish the new content, I am populating all mandatory properties, am I doing something stupid here?

  • Nicholas Westby 2054 posts 7103 karma points c-trib
    Aug 20, 2015 @ 19:25
    Nicholas Westby
    0

    Does it create the new content (in an unpublished state)?

    I assume there is already a parent node with ID 1102 and that it is published, along with all of its ancestors.

    and I assume that you provided a proper content type alias (e.g., "BlogPost") rather than the actual string "alias".

    Do you get errors (exceptions or entries in the Umbraco log)?

    What specific version of Umbraco are you using?

    Have you tried refreshing the page to see if the new content node is there?

  • Chris Lord 58 posts 211 karma points
    Aug 20, 2015 @ 19:31
    Chris Lord
    0

    Yep content is created, but as you said unpublished state. It all looks good in backend, the parent is published, and all property values are populated, correct doc type set etc.

    The parent was initially set to use list view, but changing this makes no difference. The parent is a protected page, the whole site is, so maybe that is the issue, it seems to create the new page as a protected page though!?

    v7.3.0-beta3

  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    Aug 20, 2015 @ 19:50
    Dan Diplo
    102

    You should use:

    var status = cs.SaveAndPublishWithStatus(c);
    

    Then check the value of the status object to actually find out what has happened. My hunch is that you have some mandatory properties that you haven't completed and hence publish is failing.

    You can check status.Success to see if it was successful or not.

    You can check status.Result.StatusType to get a more detailed status.

    You can check status.Result.InvalidProperties to see which (if any) properties failed.

  • Chris Lord 58 posts 211 karma points
    Aug 20, 2015 @ 19:57
    Chris Lord
    0

    Thanks Dan,

    I have a "Hide in Navigation" check box hidden on the "Properties" tab that stupidly I thought would default to false, as soon as I set the value to false the content is published ok.

    @Nicholas, thank you for your help as well.

    Cheers

    Chris

Please Sign in or register to post replies

Write your reply to:

Draft