Search code examples
asp.netumbraco

Add data programmatically to an umbraco node


I need to add some value to my umbraco node. I had tried something like this

Node node = Node.GetCurrent();
node.GetProperty("pass_word").Value = password.ToString()

But it throws error that it is read only.Can any one give any suggestion?


Solution

  • Umbraco caches the nodes' properties in an xml file, called umbraco.config. When you use NodeFactory to access a node's properties, it is pulling from the cache, and therefore read only.

    To actually edit the data found in the database and then in turn have it published to the cache you will need to use the Document class. See Difference between Node and Document for more details.

    Here's an example:

    int id = Node.GetCurrent().Id;
    Document node = new Document(id);
    node.getProperty("pass_word").Value = password.ToString();
    node.Publish(new User(0));
    umbraco.library.UpdateDocumentCache(id);