Extract all files in the file repository order by 'last modified'

Question: How do I extract the last modified file from the file repository?
The following script lists all entries in the file repository ordered by 'last modified'. If you are only interested in the last modified file, simply alter the 'count' parameter in the call to the search method to 1 and use the first SearchHit of the iterator.

var utils = request.getAttribute("sitevision.utils")
var fileRepos = utils.getResourceLocatorUtil().getFileRepository();
var orderByField = new Packages.senselogic.sitevision.api.search.SearchSortField("modified", false);
var orderBy = new ArrayList();
var query = "path:" + fileRepos.getIdentifier();

var result = utils.getSearchUtil().search(query ,orderBy ,0 , 100);
for (var i = result.getHits(); i.hasNext();)
   var hit = i.next();
   var n = hit.getNode();
   out.println(n.getName() + ": "
         + n.getProperty("lastModifiedDate").getDate().getTime()
         + "<br />");

Denna sida publicerades: 2016-11-14

Skriv ut PDF-avsnitt

Hjälpte informationen på den här sidan dig?

Missa inga nya rön, tips och tricks! Prenumerera på insite!

Find us!

SiteVision AB (Headquarter)
Vasagatan 10
702 10 Orebro

Info: +46 19-17 30 30
Support: +46 19-17 30 39

Latest Tweets