Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ifrahim/9213564 to your computer and use it in GitHub Desktop.
Save ifrahim/9213564 to your computer and use it in GitHub Desktop.
Unpublish scheduled page in Umbraco using Razor
@inherits umbraco.MacroEngines.DynamicNodeContext
@using umbraco.BusinessLogic;
@using umbraco.cms.businesslogic.web;
@{
var thisModel = @Model;
foreach (var page in thisModel.Children)
{
var doc = new Document(page.Id);
var publishAt = doc.ReleaseDate;
var removeAt = doc.ExpireDate;
if(removeAt.ToString() != “1/1/0001 12:00:00 AM”)
{
@(page.Name + ” has to be unpublished at ” + doc.ExpireDate) <br />
if(removeAt < DateTime.Now) {
doc.UnPublish();
doc.ExpireDate = DateTime.Parse(“1/1/0001 12:00:00 AM”);
umbraco.library.RefreshContent();
@(page.Name + ” has been unpublished”) <br />
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment