Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more

How to get the current version of the a page

Vote:
 

Hi

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.

#131370
Jul 22, 2015 12:25
Vote:
 

Hi,

To work with versions you could use IContentVersionRepository:

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

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

#131373
Jul 22, 2015 12:31
Vote:
 

So you could use Id from your PageReference:

var pageReference = ....

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

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

#131375
Jul 22, 2015 12:37
Vote:
 

The answer is 

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

#131378
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.