This articles provides a discussion and a sample to pull a page revision for an Episerver page.
It may be necessary to retrieve certain versions of page content. The IContentRepository or IContentLocator will always return the latest version of the content. If one needs a certain revision then the API is IContentVersionRepository.
There is one word of caution about IContentVersionRepository. Episerver doesn't provide any form of caching when working with different versions of the CMS content. Episerver will only cache the latest/published version of a page and this needs to be kept in mind.
For a sample please see below.
var contentReference = new ContentReference(1);
var contentVersionRepository = ServiceLocator.Current.GetInstance<IContentVersionRepository>();
var versions = contentVersionRepository.List(contentReference); versions.OrderByDescending(x => x.Saved).FirstOrDefault(version => version.IsMasterLanguageBranch);
The code above uses the List() method to get all the versions for the content reference that we passed in. We then filter by the OrderDescending method on the Saved Date to get the latest and then we use IsMasterLanguageBranch to check that the version matches the master language branch. If there no multi-language environment, this can be ignored.