How To Check If An Episerver Page Is Published Or Not

There are many times when you need to figure out if an Epiesrver page is published, or not, with the two most common scenarios being multi-language pickers and SEO alternative URL listing.  

In this tutorial, you will find out how you can use the IPublishedStateAssessor to achieve this.

The IPublishedStateAssessor API

As the name implies, the IPublishedStateAssessor can be used to figure out a page PublishedState. To use the API, you can simply inject it in, like you would any other Episerver API.  I recommend that you use constructor injection, as the ServiceLocator is an anti-pattern, however, to make this demo simple to understand, I'm using it.

public bool IsContentPublished(IContent content)
{
     var repository = ServiceLocator.Current.GetInstance<IPublishedStateAssessor>();
     return repository.IsPublished(content, PagePublishedStatus.Published);
}

Using this API will ensure that the pages have been published and that it hasn't expired. You pass in the IContent and you get a yes/no back. Simple!

submit to reddit

Jon D Jones

Software Architect, Programmer and Technologist Jon Jones is founder and CEO of London-based tech firm Digital Prompt. He has been working in the field for nearly a decade, specializing in new technologies and technical solution research in the web business. A passionate blogger by heart , speaker & consultant from England.. always on the hunt for the next challenge

Back to top