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.
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.
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 ?
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
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
yup, it worked, thank you Alex.
David, yup I noticed that and used the other method already.
is working on a reply...