4

I would like to add a button into the Web Part Tools ribbon section.

enter image description here

I have looked in CMDUI.XML to find the other buttons which are in this section and it appears they should be under Ribbon.WebPartOption. and i have tried a bunch of different paths under this but havent managed to get a button to show up. Below is my current code:

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
    <CustomAction
        Id="AddAsDashboardItem"
        Location="CommandUI.Ribbon"
        Sequence="5">
        <CommandUIExtension>
            <CommandUIDefinitions>
                <CommandUIDefinition Location="Ribbon.WebPartOption.Properties.Controls._children">
                    <Button
                        Id="Ribbon.WebPartOption.Commands.AddAsDashboardItemButton"
                        Command="AddAsDashboardItem_Button"
                        Sequence="5"
                        Image16by16="/_layouts/images/Dashboard2010/AddDashboardItem_16x16.bmp"
                        Image32by32="/_layouts/images/Dashboard2010/AddDashboardItem_32x32.bmp"
                        LabelText="Add As Dashboard Item"
                        TemplateAlias="o1" />
                </CommandUIDefinition>
            </CommandUIDefinitions>
            <CommandUIHandlers>
                <CommandUIHandler
                  Command="AddAsDashboardItem_Button"
                  CommandAction="javascript:alert('SharePoint ribbon button');" />
            </CommandUIHandlers>
        </CommandUIExtension>
    </CustomAction>
</Elements>

Does anyone know what location i need to put a button in this section of the ribbon?

EDIT

I tried to add it into my own group and I got the following:

enter image description here

There's a group there but no button. My code below:

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
    <CustomAction
        Id="Ribbon.WebPartOption.Dashboard"
        Location="CommandUI.Ribbon"
        Sequence="5">
        <CommandUIExtension>
            <CommandUIDefinitions>
                <CommandUIDefinition Location="Ribbon.WebPartOption.Groups._children">
                    <Group
                        Id="Ribbon.WebPartOption.Dashboard.Group"
                        Sequence="70"
                        Title="Dashboards"
                        Template="Ribbon.Templates.ManageViewsGroup">
                        <Controls Id="Ribbon.WebPartOption.Dashboard.Group.Controls">
                            <Button
                                Id="Ribbon.WebPartOption.Dashboard.AddAsDashboardItemButton.Button"
                                Command="Ribbon.WebPartOption.Dashboard.AddAsDashboardItemButton.Command"
                                Sequence="1"
                                Image16by16="/_layouts/images/Dashboard2010/AddDashboardItem_16x16.bmp"
                                Image32by32="/_layouts/images/Dashboard2010/AddDashboardItem_32x32.bmp"
                                LabelText="Add As Dashboard Item"
                                TemplateAlias="o1" />
                        </Controls>
                    </Group>
                </CommandUIDefinition>
            </CommandUIDefinitions>
            <CommandUIHandlers>
                <CommandUIHandler
                  Command="Ribbon.WebPartOption.Dashboard.AddAsDashboardItemButton.Command"
                  CommandAction="javascript:alert('SharePoint ribbon button');" />
            </CommandUIHandlers>
        </CommandUIExtension>
    </CustomAction>
</Elements>

EDIT2:

It ended up that I also needed to define scaling options. Below is a working example:

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
    <CustomAction
        Id="Ribbon.WebPartOption.Dashboard"
        Location="CommandUI.Ribbon"
        Sequence="5">
        <CommandUIExtension>
            <CommandUIDefinitions>
                <CommandUIDefinition Location="Ribbon.WebPartOption.Groups._children">
                    <Group
                        Id="Ribbon.WebPartOption.Dashboard.Group"
                        Sequence="70"
                        Title="Dashboards"
                        Template="Ribbon.Templates.Flexible2">
                        <Controls Id="Ribbon.WebPartOption.Dashboard.Group.Controls">
                            <Button
                                Id="Ribbon.WebPartOption.Dashboard.AddAsDashboardItemButton.Button"
                                Command="Ribbon.WebPartOption.Dashboard.AddAsDashboardItemButton.Command"
                                Sequence="1"
                                Image16by16="/_layouts/images/Dashboard2010/AddDashboardItem_16x16.bmp"
                                Image32by32="/_layouts/images/Dashboard2010/AddDashboardItem_32x32.bmp"
                                LabelText="Add As Dashboard Item"
                                TemplateAlias="o1" />
                        </Controls>
                    </Group>
                </CommandUIDefinition>
                <CommandUIDefinition Location="Ribbon.WebPartOption.Scaling._children">
                    <MaxSize Id="Ribbon.WebPartOption.Dashboard.MaxSize"
                             GroupId="Ribbon.WebPartOption.Dashboard.Group"
                             Sequence="20"
                             Size="LargeLarge"/>
                </CommandUIDefinition>
                <CommandUIDefinition Location="Ribbon.WebPartOption.Scaling._children">
                    <MaxSize Id="Ribbon.WebPartOption.Dashboard.MediumMedium"
                             GroupId="Ribbon.WebPartOption.Dashboard.Group"
                             Sequence="30"
                             Size="MediumMedium"/>
                </CommandUIDefinition>
                <CommandUIDefinition Location="Ribbon.WebPartOption.Scaling._children">
                    <MaxSize Id="Ribbon.WebPartOption.Dashboard.Popup"
                             GroupId="Ribbon.WebPartOption.Dashboard.Group"
                             Sequence="20"
                             Size="Popup"/>
                </CommandUIDefinition>
            </CommandUIDefinitions>
            <CommandUIHandlers>
                <CommandUIHandler
                  Command="Ribbon.WebPartOption.Dashboard.AddAsDashboardItemButton.Command"
                  CommandAction="javascript:alert(getId());" />
            </CommandUIHandlers>
        </CommandUIExtension>
    </CustomAction>
</Elements>
1
  • If you don't end up with a declarative way of approaching this you could also add this using the Ribbon Javascript library as needed. Commented Apr 3, 2013 at 5:47

2 Answers 2

1

I think that the main problem is in registration id and type.

RegistrationId="101"
RegistrationType="List"

You tells SharePoint to insert you action to the ribbon of a list that is a document library. See this post to understand how to add action into existing tab.

4
  • Thanks, your right these dont belong here, i removed them and simplified my example to match more closely to the COB one but i still cant get it to go. I think the location string is still wrong. Any idea where i can go to find out the correct location string?
    – undefined
    Commented Apr 3, 2013 at 8:45
  • 1
    Can you use this example? All examples that I found contains definition for a custom group. Is it ok for you?
    – Alexander
    Commented Apr 3, 2013 at 9:01
  • I gave that a go and the group shows up but not the button. I guess that means its probably something other than the location. I cant see any other differences between my code and the COB or the example you referenced. Im pretty sure the actual button code is OK as i tried it earier on a regular list ribbon and it worked fine.
    – undefined
    Commented Apr 3, 2013 at 9:29
  • 1
    I do not see any reason. Only difference is a image extension. You use bmp, in the example it is a png. Also there are scaling options.
    – Alexander
    Commented Apr 3, 2013 at 10:21
0

I know this is an old question but I found a quickfix in Sharepoint 2010.

If you use SharePoint Designer, go to Lists and Libraries, then select the List you require the Custom Action to be placed in.

In the bottom right there will be a Custom Actions window, where you can add the Custom Actions and import the picture etc.

Doing this will add the custom action to the actual list itself, and not the Web Part that you may place on a page.

Once the Custom Action is in the List, go to your Web Part on the Page that you put it on.

Edit the page, select the Web Part -> Web Part Tools, then "Web Part Properties". This will bring up the Properties window on the right hand side of the screen. You may have to scroll over.

The very top of the properties window asks for the "Toolbar Type". Select "Full Toolbar". Then "OK". Then Save and Close the edits.

This will put your Custom Actions into the Web Part added to that particular page.

Hope this helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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