Copied to clipboard

Flag this post as spam?

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


  • Andrei 4 posts 35 karma points
    Sep 23, 2014 @ 12:41
    Andrei
    0

    is it possible to set a property value from code behind ?

    Hello,

    I am using Umbraco 7 and I am trying to find a way to update a property value from a controller.

    I have a specific document type with some properties, I can access them just fine and get their values but can't seem to find a way to set them. Yes, before you ask, I know those can be set from the umbraco back end by users, but I have a very specific functionality and I have a service which needs to update some properties on its own. 

    Is it possible ?

     

  • Alex Skrypnyk 6133 posts 23952 karma points MVP 7x admin c-trib
    Sep 23, 2014 @ 12:51
    Alex Skrypnyk
    100

    Hi Andrei,

    Welcome to Umbraco community. Of course, it's possible.

    Try to use .SetValue(string propertyTypeAlias, object value) method.

    http://our.umbraco.org/documentation/Reference/Management-v6/Models/Content

    And don't forget to republish node after that.

    contentService.SaveAndPublish(node);

    THanks, Alexandr

  • David Brendel 792 posts 2970 karma points MVP 3x c-trib
    Sep 23, 2014 @ 14:49
    David Brendel
    0

    Hi Andrei,

    Alex posted the right answer. Of course it's possible to update values from code behind. If you running on the latest v7 versions of Umbraco you may notice that the SaveAndPublish-ethod of the content service is marked as deprecated or obsolte. The newest method is "SaveAndPublishWithStatus" which works like the above mentioned one but returns a status if the publishing was successfull if you want to check that in your code.

    Also I would suggest you to use the contentservice for creating, updating and saving/publishing of content. http://our.umbraco.org/Documentation/Reference/Management-v6/Services/ContentService

    David

  • Andrei 4 posts 35 karma points
    Sep 23, 2014 @ 16:05
    Andrei
    1

    yup, it worked, thank you Alex.

    David, yup I noticed that and used the other method already. 

Please Sign in or register to post replies

Write your reply to:

Draft