When you work with content in the CMS you may need to work with older versions. When you use the API's like IContentRepository or IContentLocator they will always return you the latest version of the content. 99% of the time you won't need to worry about different versions, if you do however, you need to be aware of the IContentVersionRepository.
One word of caution about IContentVersionRepository. Episerver doesn't provide any form of caching when you work with different versions of the CMS. Episerver will only cache the latest/published version of a page. If you need to use IContentVersionRepository you need not keep this in mind. In most situations you will probably only ever use IContentVersionRepository to create some back-end plug-in or feature, but if you find yourself needing to use this in production code then you should look into caching the results as well.
var contentReference = new ContentReference(1);
var contentVersionRepository = ServiceLocator.Current.GetInstance<IContentVersionRepository>();</pre>
var versions = contentVersionRepository.List(contentReference);
versions.OrderByDescending(x => x.Saved)
.FirstOrDefault(version => version.IsMasterLanguageBranch);
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