I want to write script that gets all versions of documents in site and deletes all of them except latest version either using CSOM or SPServices. I have found some information on net but could not find concrete method to delete. Guidance will be appreciated


You could utilize SP.FileVersionCollection.deleteAll Method for that purpose:


var fileName = '/sites/news/Pages/default.aspx';

var ctx = SP.ClientContext.get_current();
var versions = ctx.get_web().getFileByServerRelativeUrl(fileName).get_versions();
      console.log('File versions have been deleted');   

function logError(sender,args)
  • we need to write : ctx.load(versions) before ctx.executeQueryAsync correct ? – Learner Mar 4 '15 at 21:22
  • nope, there is no need to load versions since you are going to delete them – Vadim Gremyachev Mar 4 '15 at 21:27
  • Does that mean load is only needed for select type of queries ? – Learner Mar 5 '15 at 19:42
  • For select mostly but also could be useful for update operations – Vadim Gremyachev Mar 5 '15 at 19:44
  • ok thanks but here we updated versions but havent used load. Is there specific scenario when we need load and when we do not ? – Learner Mar 6 '15 at 16:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.