Copied to clipboard

Flag this post as spam?

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


  • Roger Withnell 128 posts 613 karma points
    May 16, 2017 @ 16:27
    Roger Withnell
    0

    Save a node programmatically

    I'm using ContentPublished event to programmatically change the value of a property with:

    node.SetValue("property", 0);

    This works fine but the new value of the property is not saved. How do I do that?

    Your help would be much appreciated.

    Thanking you in anticipation.

    Roger

  • Craig Mayers 164 posts 508 karma points
    May 16, 2017 @ 16:57
    Craig Mayers
    100

    Hi Roger,

    You need to use the ContentService api.

    See the following reference: https://our.umbraco.org/documentation/reference/management/services/contentservice

    If you just want to save and not publish:

    ApplicationContext.Current.Services.ContentService.Save(IContent node)
    

    If you want to save and publish:

    ApplicationContext.Current.Services.ContentService.SaveAndPublishWithStatus(IContent node)
    

    Good luck!

    Regards

    Craig

  • Alex Skrypnyk 6133 posts 23952 karma points MVP 7x admin c-trib
    May 16, 2017 @ 16:59
    Alex Skrypnyk
    0

    Hi Roger

    ContentPublished event raised when ContentService.Publish is called in the API and after data has been published. So you have to call Publish method or Save after node.SetValue("property", 0);

    Another possibility is to use Publishing event.

    Thanks,

    Alex

Please Sign in or register to post replies

Write your reply to:

Draft