I have added a new button to the SharePoint ribbon for document libraries. This all works well and the button is enabled / disabled depending on the number of items selected... fine!

I want to improve this by disabling the button when a folder is selected similar to how the standard SharePoint 'email a link' button works. Can anyone offer any advice on how to approach this? I have Googled around, but have not been able to find anything.

The code I currently have is as follows:

          <Button Id="Muhimbi.SharePoint.DocumentConverter.PDF.Ribbon.Documents.Copies.Controls.ConvertAndDownload.Button"
                  TemplateAlias="o1" />
          CommandAction="javascript:window.location='{SiteUrl}/_layouts/Muhimbi.PDFConverter/Convert.aspx?action=ConvertAndDownload&amp;ListId={ListId}&amp;ItemId=' + SP.ListOperation.Selection.getSelectedItems()[0].id + '&amp;Source=' + window.location"
          EnabledScript="javascript:function singleEnable()
            var items = SP.ListOperation.Selection.getSelectedItems();
            var ci = CountDictionary(items);
            return (ci == 1);
          singleEnable();" />

Use the fsObjType property:

  var items = SP.ListOperation.Selection.getSelectedItems();
  (items.length == 1 &amp;&amp; items[0].fsObjType == 0);"
  • I don't believe it! First time I got an answer to a non obvious question on this site :-) Wooho, thanks 'Bender'. – Jeroen Ritmeijer - Muhimbi Sep 22 '10 at 17:22

Can u alert what do you get when you select a folder using SP.ListOperation.Selection.getSelectedItems();

  • For each selected item returned from SP.ListOperation.Selection.getSelectedItems(), you can use the fileSystemObjectType property of SP.ListItem class to test if it is a folder or not. Accordingly you can enable or disable the ribbon button.. – Vivek Sep 8 '10 at 13:48
  • I am fairly sure it just returns the IDs of the items after calling getSelectedItems(). How can I go from the ID to a full blown SP.ListItem object? – Jeroen Ritmeijer - Muhimbi Sep 8 '10 at 21:03
  • You would need to go a bit long way from here.. First get hold of the SPList object by SP.ListOperation.Selection.getSelectedList(); now this would againg return a GUID of the list. Further get the real SPlist object using the web.getLists() and iterat for your list GUID. Then you would need to get your ListItem using SP.List.getItemById(id); and go from here.. – Vivek Sep 10 '10 at 17:47

protected by Community Jun 20 '11 at 9:14

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

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