Change a page property while it gets published


I want to automatically update a page property as it gets published. 

I have implemented a delegate for the PublishedPage event [EPiServer.Core] - it's firing whenever a page gets published. I can also access the PageData for the published page during the PublishedPage event. No problems there.

What I want to be able to do is update a property on the page that has just been published during the PublishedPage event. I would rather avoid having to create a new published version too.

Have tried creating a writeable clone of the page, changing the property and executing the Save method, but no dice no matter what I use in the SaveAction argument... am I doing something wrong here?

//* Create a writable clone
PageData thisPage = e.Page.CreateWritableClone();
//* Update the property
thisPage["PropertyName"] = "Updated during the PublishedPage event";
//* Save
DataFactory.Instance.Save(myWritablePage, SaveAction.ForceCurrentVersion);

Ta for any pointers...



May 14, 2009 21:47

Check out the Publish_ing_Page event instead, it fires *before* the page gets saved to the database, and gives you the chance to make modifications inline to page properties.

For example:

EPiServer.DataFactory.Instance.PublishingPage += new EPiServer.PageEventHandler(DF_PublishingPage);

void DF_PublishingPage(object sender, EPiServer.PageEventArgs e)
  e.Page.PageName = "Modified " + e.Page.PageName;


May 15, 2009 11:23

Cheers Johan.

Have also found a way of doing it in the PagePublished event:

DataFactory.Instance.Save(writablePage, SaveAction.CheckIn | SaveAction.ForceCurrentVersion);

May 15, 2009 11:45

Yeah, that works too, but requires you to hit the database twice for every page publish.


May 15, 2009 11:50
Ah - good thinking. Cheers for the help, mate.
May 15, 2009 16:41
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* 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.