I have a custom button on ribbon, which performs some action with current folder (download folder content as zip package). I want to disable this button in case if current folder doesn't contain any items - neither files nor subfolders. Could you please help me with JavaScript code for "EnabledScript" property of "CommandUIHandler"?

1 Answer 1


You could extract the current folder location from the RootFolder parameter of the URL of the current displayed view. Then load the folder like this:

    function GetItemCount()
      // extract folder URL from request parameter RootFolder
      var folderUrl = ...;

      var ctx = new SP.ClientContext();
      var web = ctx.get_web();
      var folder = web.getFolderByServerRelativeUrl(folderUrl);
      ctx.executeQueryAsync(function(s, a){ alert(folder.get_itemCount()) });    
  <a href='javascript:GetItemCount();'>Get item count</a>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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