Change a page property while it gets published

Vote:
 

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...

 

 

#29793
May 14, 2009 21:47
jo
Vote:
 

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;
}

/johan

#29798
May 15, 2009 11:23
Vote:
 

Cheers Johan.

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

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

#29800
May 15, 2009 11:45
jo
Vote:
 

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

/johan

#29802
May 15, 2009 11:50
Vote:
 
Ah - good thinking. Cheers for the help, mate.
#29809
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.