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



#29793 May 14, 2009 21:47
  • jo
    Member since: 1996

    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;


    #29798 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);

    #29800 May 15, 2009 11:45
  • jo
    Member since: 1996

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


    #29802 May 15, 2009 11:50
    Ah - good thinking. Cheers for the help, mate.
    #29809 May 15, 2009 16:41