Copied to clipboard

Flag this post as spam?

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


  • Mike 12 posts 34 karma points
    Sep 01, 2011 @ 10:21
    Mike
    1

    How do i update an Umbraco Node's property value from the code behind?

    Hello,

    I've been stuck on this for a day now.

    How can i update a Node's property from the code behind for ASP.Net?

    All the umbraco.library.NodeFactory.Node methods are Get's, none seem to set a property value.

    I tried to update the value in the database directly which seems to work, but because i dont know how to publish the content from my code behind the vlaue gets ignored.

    Any help will be greatly appreciated!

    Many thanks
    Mike

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Sep 01, 2011 @ 11:08
    Dirk De Grave
    0

    Hi,

    nodeFactory.Node is for published xml only, so it's always readonly. if you need to update a doc's property, use

    var doc = new Document(1234);
    doc.GetProperty("propertyAlias").Value = newValue;
    doc.Save();

    Cheers,

    /Dirk

  • Mike 12 posts 34 karma points
    Sep 01, 2011 @ 11:46
    Mike
    0

    Thanks dirk thats a big help.

    When i use the above it changes the value in umbraco which is cool but it doesnt publish the item so the value on the site does not change. Should i use doc.Publish after doc.Save?

    If so it asks for a user, what user should i pass in?

    Thanks,

    Mike

  • Rich Green 2246 posts 4008 karma points
    Sep 01, 2011 @ 11:49
  • Mike 12 posts 34 karma points
    Sep 01, 2011 @ 12:07
    Mike
    0

    Rich that is exactly what i've been searching for! Many thanks that works fine. Thanks guys.

  • Rich Green 2246 posts 4008 karma points
    Sep 01, 2011 @ 12:09
    Rich Green
    0

    Hey Mike,

    Glad you got it working, if you can mark a post as a 'Solution' then it can help others looking for the same info.

    Cheers

    Rich

  • Hendy Racher 863 posts 3849 karma points MVP 2x admin c-trib
    Sep 01, 2011 @ 12:16
    Hendy Racher
    0

    Hi,

    btw, if you have uComponents installed, you can also use uQuery methods to set property values:

    using uComponents.Core;
    using uComponents.uQueryExtensions;

    Node node = uQuery.GetCurrentNode();
    node.SetProperty("propertyAlias", valueObject);
    node.Publish(true);

    HTH,

    Hendy

Please Sign in or register to post replies

Write your reply to:

Draft