Created
February 25, 2014 17:24
-
-
Save ifrahim/9213564 to your computer and use it in GitHub Desktop.
Unpublish scheduled page in Umbraco using Razor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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