StopPublish is readonly?


I'm fairly new to EpiServer so maybe this question has been answered before. I couldnt find any easily but here goes;

When my page is saved, I check certain fields and when a field is set, the page should be archived. I want to set StopPublish to a date in the past but when I excute the code in the page I get a validator error; 

  • The property PageStopPublish is read-only.

I don't get this, why was the property settable in C# in the first place? I don't have any custom validators regarding StopPublish

Oct 26, 2018 10:16

Have you created a writable clone of the page? Try setting the property directly with page["PageStopPublish"] (or MetaDataProperties.PageStopPublish).

At least previously this built in property had to be set like this I think.

Oct 26, 2018 10:41

Hi Johan,

The page is a new instance all together. I've tried setting the property directly; still the same exception is thrown direclty. The MetaDataProperties doesn't seem to be accessible. That property doesn't exisist on my PageData object

Thanks for the effort tho

Oct 26, 2018 12:26

Hmm can you provide some more info about the context in which you are doing this? Is it in the save event? The following code works:

Edit: should be noted, this is with cms version 11

var c = ServiceLocator.Current.GetInstance<IContentRepository>();
var p = c.GetDefault<ArticlePage>(ContentReference.StartPage);
p.Name = "asjdlkajsd";
p.StopPublish = DateTime.Now;
c.Save(p, SaveAction.Publish);

(It is created as expired).

Edited, Oct 26, 2018 12:39

I hook on the 'EventsSavedContent' in a IInitializableModule  
Of course my accutal code is more elaborate

  private void EventsSavedContent(object sender, ContentEventArgs e)
//((PageData)e.Content).StopPublish = DateTime.Now.AddSeconds(-1);
e.Content["PageStopPublish"] = DateTime.Now.AddSeconds(-1);

Oct 26, 2018 13:42

In that event I believe the page has already been created and saved to the repository so based on the code you provide you need to create a new editable version and save that yourself i.e.: 

var newPage = (e.Content as PageData).CreateWritableClone();
newPage.StopPublish = DateTime.Now;
EPiServer.ServiceLocation.ServiceLocator.Current.GetInstance<IContentRepository>().Save(newPage, SaveAction.ForceCurrentVersion | SaveAction.Publish);
Oct 26, 2018 15:57

I see now, the item is not a writeableClone to begin with

Oct 26, 2018 16:01

not sure if you have reasons not to, but it sounds like listening to Saving/Publishing event would make things easier to you

Oct 26, 2018 16:16
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* 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.