We are currently working on something which saves changes to pages. The user then needs to be able to publish these changes later. Publishing is easy with the Save method in the content repository, the problem is I can't figure out how to get the pages in their latest saved version to then publish those changes.
Any calls to Get or GetChildren only get me the latest published version of the page. How can I get the absolute latest version, which may not be published?
You can try to play around with content version repository.
var repository = ServiceLocator.Current.GetInstance<IContentVersionRepository>();
// enlists all available versions
var versions = repository.List(pageReference);
In the list of available versions you may try to order by saved date to get latest "valid" draft.
Getting the latest version of several pages might use alot of performance. I'd suggest that you cache your result.
Note that you can create dependencies to content in EPiServer by using DataFactoryCache.CreateDependency(ContentReference) so when you update that specific page, your cache will be invalidated.
Thanks! That content version repository looks almost exactly what I am looking for, however I'm having issues actually getting the PageData for a given version.
I can get the latest version by using the Status and Saved properties, but once I have it I don't know what I can do to get to that version's page properties?
Each ContentVersion contains a ContentLink that is a ContentReference, containing the version number.
You can use that to get the Content as any other ContentReference.
Ah right ok, I saw the ContentLink on the object but I didn't realise it was actually associated with the version.
That should work great, thanks!