Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
I am trying to log node name changes in a property for future reference/usage.
According to the documentation about IRememberBeingDirty, it is possible to access information about whether a property was changed.
What I am trying to do is get the current node Name and the previous node Name to compare.
When I debug this code snippet ('node' is an IContent entity):
var dirty = (IRememberBeingDirty)node;
var nameChanged = dirty.WasPropertyDirty("Name");
"nameChanged" is false (though I did change the Node name for my test)
If I hover over the "dirty" variable... I see properties "Name" = with the new name, and "NodeName" with the old name - but I can't figure out how to access "NodeName" via code.
If I try this:
var oldNodeName = ((Content)dirty).NodeName;
var currentNodeName = node.Name;
".NodeName" had the red squiggle underline and says "Cannot access internal property 'NodeName' here"
So... how can I get to that data?
IRememberBeingDirty only stores details of which properties were changed, not the previous values, so I don't think it can help you. Could you do your checks in the Saving event? At that stage, you can still get the previous version from the ContentService, since the updated version hasn't been saved yet.
I use this code to populate umbracoUrlName with the original URL when a document is renamed:
void Content_Saving(IContentService sender, SaveEventArgs<IContent> e)
foreach (var c in e.SavedEntities)
// Set umbracoUrlName if a published document is renamed and umbracoUrlName is empty
&& c is ICanBeDirty
&& (c as ICanBeDirty).IsPropertyDirty("Name")
&& String.IsNullOrEmpty( c.GetValue<string>("umbracoUrlName"))
var previousVersion = sender.GetById(c.Id);
NodeName seems to be left over from preparation for the language variant support that ended up being in version 8. It's intended to store the name in the default language when a node has language variants. It ends up storing the original name because it isn't being updated when you save content with a new name, but it's not intended to be a way to get the original name.
Thanks so much, Steve!
That is exactly what I needed.
I was using an event attached to "ContentService.Saving" but wasn't aware of how to access the "old" content node values.
I've got it working now :-)
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted