Try our conversational search powered by Generative AI!

Saving page programmatically


Trying to set a fallback image on a product.
Trying to get it from parent (that is category)

public class ContentEvents : IInitializableModule
public void Initialize(InitializationEngine context)
var events = context.Locate.ContentEvents();
events.PublishingContent += EventsPublishingContent;


private void EventsPublishingContent(object sender, ContentEventArgs e)
if (e.Content is RouteProductContent)
var content = e.Content as ProductContent;
if (content.IconImage != null) return;

var parentContentReference = content.ParentLink;
var repository = ServiceLocator.Current.GetInstance();
var category = repository.Get(parentContentReference);
if (category.IconImage != null)
var clone = content.CreateWritableClone() as RouteProductContent;
clone.Property["IconImage"] = new PropertyContentReference(category.IconImage);

// have also tried with
clone.Property["IconImage"].value = category.IconImage;
// and
clone.IconImage = category.IconImage;


public void Uninitialize(InitializationEngine context)
var contentEvents = ServiceLocator.Current.GetInstance();
contentEvents.PublishingContent -= EventsPublishingContent;

Jun 08, 2017 21:32

Assuming that the problem is not getting any propterydata on the clone.

You need to call save on the clone, "repository.Save(clone, SaveAction.Publish);" for the change to be persistant.


Jun 08, 2017 22:37

Oskar's answer is correct - the change to any content (not just catalog content, but also CMS content) needs to be explicitly saved. It'll not be saved automatically when you set it.

Apparently I didn't read the question carefully, for IContentEvents you don't have to publish it explicitly

Edited, Jun 09, 2017 10:26

Not working as aspected:

Both tried with

var content = e.Content as RouteProductContent;
if (content.IconImage != null) return;

var parentContentReference = content.ParentLink;
var repository = ServiceLocator.Current.GetInstance<IContentRepository>();
var category = repository.Get<SondermautCategoryNodeContent>(parentContentReference);
if (category?.IconImage != null)
var clone = content.CreateWritableClone();
clone.Property["IconImage"].Value = category.IconImage;

and with 


On publishing event and published event.

Not saving the value

Jun 16, 2017 11:31

with repository.Save(clone, SaveAction.Save, AccessLevel.Publish);

Jun 16, 2017 11:48
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.