SaaS CMS has officially launched! Learn more now.

Unpublish page programmatically


Hi guys:


First time using the forum, hope I can get some help here.

I am currently working on a project where I need to unpublish pages programmatically. If the information does not exist anymore in the source, then I need to unpublish those pages in my EPiServer installation. I found how to publish pages programmatically but cannot find the unpublish option. Any help or tips will be appreciated.


Feb 22, 2011 11:47

Just set the Stop publish date to a date that has passed.

Feb 22, 2011 13:03

Thanks for the reply Erik, I tried using Stop publish date but must be doing something wrong. I tried not using the Instance in the PageDataCollection but it does not work either. I get this error message from the server "The property PageStopPublish is read-only."

public static PageReference parent = new PageReference(10);

public PageDataCollection pageCollection = DataFactory.Instance.GetChildren(parent);

public void unpublishOldPages()
foreach (PageData p in pageCollection)
if (//Some code)
p.StopPublish = DateTime.Now;

Edited, Feb 22, 2011 14:22

You need to create a writable clone of the pagedata object, and then of course save it.

in the foreach

PageData writablePage = p.CreateWrtableClone();

writablePage.StopPublish = DateTime.Now;

Datafactory.Instance.Save(writablePage, yourparams...);

Feb 22, 2011 14:25

It worked perfect. Thanks Erik

Feb 22, 2011 14:49
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.