set value for the built in properties episerver, StopPublish

422 Views Asked by At

Im trying to enforce the user to set a DateTime for StopPublish

[Required]     
public virtual DateTime EnforceStopPublish
{ get; set; }

    public override DateTime? StopPublish
    {
        get { return EnforceStopPublish; }
    }

didn't work, is there another possible way, maybe by an Publishing event? example.

thanks in advance

2

There are 2 best solutions below

2
Ted Nyberg On

Never tried it on the StopPublish property (not sure about any side-effects), but could you do it with standard data annotations, i.e. a Requiredattribute on your overriding property?

0
andreasnico On

You could also do it in the SetDefaultValues method. The user will then of course be able to remove or change the stoppublishdate, but that can certanly be ok in a lot of cases.

public override void SetDefaultValues(ContentType contentType)
{
    base.SetDefaultValues(contentType);
    this[MetaDataProperties.PageStopPublish] = DateTime.Now.AddDays(5);
}