Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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"?

share|improve this question
add comment

1 Answer 1

up vote 1 down vote accepted

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>
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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