5

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:

  <CustomAction
    Id="Muhimbi.SharePoint.DocumentConverter.PDF.Ribbon.Documents.Copies.Controls.ConvertAndDownload.Action"
    Location="CommandUI.Ribbon"
    RegistrationType="ContentType"
    RegistrationId="0x0101"
    >
    <CommandUIExtension>
      <CommandUIDefinitions>
        <CommandUIDefinition
          Location="Ribbon.Documents.Copies.Controls._children">
          <Button Id="Muhimbi.SharePoint.DocumentConverter.PDF.Ribbon.Documents.Copies.Controls.ConvertAndDownload.Button"
                  Command="Muhimbi.SharePoint.DocumentConverter.PDF.Ribbon.Documents.Copies.Controls.ConvertAndDownload.Button.Command"
                  Image16by16="/_layouts/images/Muhimbi.PDFConverter/pdf16.gif"
                  Image32by32="/_layouts/images/Muhimbi.PDFConverter/pdf32.gif"
                  LabelText="$Resources:ecb_title;"
                  Sequence="12"
                  TemplateAlias="o1" />
        </CommandUIDefinition>
      </CommandUIDefinitions>
      <CommandUIHandlers>
        <CommandUIHandler
          Command="Muhimbi.SharePoint.DocumentConverter.PDF.Ribbon.Documents.Copies.Controls.ConvertAndDownload.Button.Command"
          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();" />
      </CommandUIHandlers>
    </CommandUIExtension>
  </CustomAction>
5

Use the fsObjType property:

EnabledScript="javascript:
  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
0

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

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