SaaS CMS has officially launched! Learn more now.

Unpublish page programmatically

Vote:
 

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.

Thanks

#48901
Feb 22, 2011 11:47
Vote:
 

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

#48903
Feb 22, 2011 13:03
Vote:
 

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

#48908
Edited, Feb 22, 2011 14:22
Vote:
 

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

#48909
Feb 22, 2011 14:25
Vote:
 

It worked perfect. Thanks Erik

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