1

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

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:

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

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

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.