public class RegisterUmbracoEvents : ApplicationEventHandler
{
public RegisterUmbracoEvents()
{
ContentService.Saved += Save;
}
private void Save(IContentService contentService, SaveEventArgs<IContent> saveEventArgs)
{
foreach (var node in saveEventArgs.SavedEntities)
{
// is the item pending?
if (node.Pending())
{
// is it already in the pending folder?
if (node.ParentId != (int)FolderNodeIds.Pending)
{
// no, so move it to the pending folder
contentService.Move(node, (int)FolderNodeIds.Pending);
}
}
else
{
// otherwise, move to other known folder
contentService.Move(node, 2459);
}
}
}
}
The last line contentService.Move(node, 2459); keeps raising the event causing a stack overflow.
I could check on the second time if the parent node id is 2459, but is there any way to say "stop raising these events now"?
Could you not set the ParentId to the new folder '2459' instead of using the move and then call save without rasing events contentService.Save(node, 0, false);
V6 Events : Saving, Moving and raiseEvents?
I'm trying to move a node via the following code.
The last line
contentService.Move(node, 2459);
keeps raising the event causing a stack overflow.I could check on the second time if the parent node id is 2459, but is there any way to say "stop raising these events now"?
Could you not set the ParentId to the new folder '2459' instead of using the move and then call save without rasing events contentService.Save(node, 0, false);
John
Thanks John,
That seems to be a better way. I'll have a further play, but this works for now! Cheers.
No problem, let me know if you find a better way.
is working on a reply...