7

I'm attempting to add a tab to the Library contextual group. So far that works inside a Document Library. I can also see my Group on the new tab, but I don't see my button (will have more than one eventually). I also do see my tab if the Document Library is in a webpart.

Here is what I want to do in the end: The tab always shows in the Library contextual group. The Group is identical for all document types, but for specific document types it will show a specific button based on the document file extension (doc, docx, xls, xlsx, etc.). The only difference for the buttons, besides images, is that they'll execute certain commands. This is in order to leverage the Word Automation Services.

    <CommandUIDefinition Location="Ribbon.LibraryContextualGroup._children">      
      <Tab Id="Ribbon.WAS.Tab" 
        Title="Conversion"
        Description="Conversion Menu"
        Sequence="1001" >
        <Scaling Id="Ribbon.WAS.Tab.Scaling">
          <MaxSize Id="Ribbon.WAS.Group.MaxSize"
            GroupId="Ribbon.WAS.Groups.Group"
            Size="OneRow" />
        </Scaling>
        <Groups Id="Ribbon.WAS.Groups">
          <Group
            Id="Ribbon.WAS.Groups.Group"
            Sequence="1"
            Description="Converts documents"
            Template="Ribbon.WAS.GroupTemplate"
            Title="Document Conversion">
            <Controls Id="Ribbon.WAS.Controls">
              <Button Id="Ribbon.WAS.Controls.ToPdf"
                Sequence="1"
                LabelText="Contextual"
                Image16by16="/_layouts/Images/WAS/16x16Placeholder.png"
                Image32by32="/_layouts/Images/WAS/32x32Placeholder.png"
                TemplateAlias="o1"/>
            </Controls>
          </Group>
        </Groups>
      </Tab>
    </CommandUIDefinition>
  </CommandUIDefinitions>
5
+100

Maybe the sequence number of the Group and Button tags isn't correct. SharePoint sequence numbers of default controls are based on multiples of 10. So to avoid collisions try changing the sequence number of the Group tag to 52 and the sequence number of the Button tag to 15 (For example).

EDIT:

You need to change the Size attribute in the MaxSize tag to the Title property value of the Layout tag.

For example if the Layout tag is like this:

<Layout 
  Title="OneLargeTwoMedium" 
  LayoutTitle="OneLargeTwoMedium"> 
  <Section Alignment="Top" Type="OneRow"> 
    <Row> 
      <ControlRef DisplayMode="Large" TemplateAlias="o1"  /> 
    </Row>
  </Section>
  <Section Alignment="Top" Type="TwoRow">
    <Row>
      <ControlRef DisplayMode="Medium" TemplateAlias="o2" />
    </Row>
    <Row>
      <ControlRef DisplayMode="Medium" TemplateAlias="o3" />
    </Row>
  </Section>
</Layout>

Change the Scaling tab from this:

<Scaling Id="Ribbon.WAS.Tab.Scaling">
 <MaxSize Id="Ribbon.WAS.Group.MaxSize"
   GroupId="Ribbon.WAS.Groups.Group"
   Size="OneRow" />
</Scaling>

To this:

<Scaling Id="Ribbon.WAS.Tab.Scaling">
 <MaxSize Id="Ribbon.WAS.Group.MaxSize"
   GroupId="Ribbon.WAS.Groups.Group"
   Size="OneLargeTwoMedium" />
</Scaling>

Complete Working Example:

<?xml version="1.0" encoding="utf-8"?>

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <CustomAction Id="Hello_world" RegistrationType="List" RegistrationId="101" Location="CommandUI.Ribbon" Sequence="5">
    <CommandUIExtension>
      <CommandUIDefinitions>
        <CommandUIDefinition Location="Ribbon.Templates._children">
          <GroupTemplate Id="Ribbon.WAS.GroupTemplate" >
            <Layout Title="bob" LayoutTitle="OneLargeTwoMedium">
              <Section Alignment="Top" Type="OneRow">
                <Row>
                  <ControlRef DisplayMode="Large" TemplateAlias="cust1" />
                </Row>
              </Section>
              <Section Alignment="Top" Type="TwoRow">
                <Row>
                  <ControlRef DisplayMode="Medium" TemplateAlias="cust2" />
                </Row>
                <Row>
                  <ControlRef DisplayMode="Medium" TemplateAlias="cust3" />
                </Row>
              </Section>
            </Layout>
          </GroupTemplate>
        </CommandUIDefinition>
        <CommandUIDefinition Location="Ribbon.LibraryContextualGroup._children">
          <Tab Id="Ribbon.WAS.Tab" Title="Conversion" Description="Conversion Menu" Sequence="501" >
            <Scaling Id="Ribbon.WAS.Tab.Scaling">
              <MaxSize Id="Ribbon.WAS.Group.MaxSize" GroupId="Ribbon.WAS.Groups.Group" Size="bob" />
            </Scaling>
            <Groups Id="Ribbon.WAS.Groups">
              <Group Id="Ribbon.WAS.Groups.Group" Sequence="52" Description="Converts documents" Template="Ribbon.WAS.GroupTemplate" Title="Document Conversion">
                <Controls Id="Ribbon.WAS.Controls">
                  <Button Id="Ribbon.WAS.Controls.ToPdf" Sequence="15" LabelText="Contextual" Command="Show_HelloWorld" Image16by16="/_layouts/images/placeholder32x32.png" Image32by32="/_layouts/images/placeholder32x32.png" TemplateAlias="cust1"/>
                </Controls>
              </Group>
            </Groups>
          </Tab>

        </CommandUIDefinition>
      </CommandUIDefinitions>

      <CommandUIHandlers>
        <CommandUIHandler Command="Show_HelloWorld" CommandAction="javascript:alert('Hello World!');" />
      </CommandUIHandlers>
    </CommandUIExtension>

  </CustomAction>
  </Elements>
  • My button still doesn't appear after not using multiples of 10. – Trevor Seward Dec 20 '12 at 20:28
  • Please try my new edits. – user3470 Dec 21 '12 at 10:56
  • I have added a complete working example. You can compare it with your existing code. – user3470 Dec 26 '12 at 21:15
0

I would make a separate button for each function, or make a polymorphic button that changes from a command called by the group command. (This is what determines if buttons should be on or off)

So make 1 button for each

Create a Group Command function that turns the groups on or off, and in this process you will be able or should be able to hide the buttons you don't want.

I think this should do it for you.

  • Could you expand on this? Sounds like you're telling me exactly what I need to do, however development isn't my day-job by any means. What I'm doing above is just for fun. I'm half wondering if my button isn't appearing because I don't have any logic to turn it on in the first place. – Trevor Seward Dec 20 '12 at 20:40
  • I would need to have a play with it, this being the case which I cannot do today. But I will if regardless because this is a interesting one indeed. – Hugh Wood Dec 21 '12 at 10:43

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.