Try our conversational search powered by Generative AI!

How to get the current version of the a page



In my site multiple editors can edit page . so a page can have multiple unpublished versions. i want to know in the backend which is the current version of page. it can not be last version all the times.

Jul 22, 2015 12:25


To work with versions you could use IContentVersionRepository:

var repository = ServiceLocator.Current.GetInstance<IContentVersionRepository>();
var id = 123;
var versions = repository.List(new ContentReference(id));
Jul 22, 2015 12:28

i dont have id of the version. i only have page reference in backend now i want to get current version of the page that is being displayed to editor or publisher when they click on the page in site pages tree list

Jul 22, 2015 12:31

So you could use Id from your PageReference:

var pageReference = ....

var repository = ServiceLocator.Current.GetInstance<IContentVersionRepository>();
var versions = repository.List(pageReference);
Jul 22, 2015 12:35

it will return all versions of that page. i want to select current version of the page(it can be or cannot be the latest version) among these versions

Jul 22, 2015 12:37

The answer is 

var commonDraft = versionRepository.LoadCommonDraft(page.ContentLink, "en");

Jul 22, 2015 13:15
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.