top of page

Create a custom tab in the SharePoint ribbon interface


Introduction:

In this article we will be seeing how to create a custom tab, group and button to the server ribbon in Sharepoint 2010. Tabs are the root of the Server ribbon and they contain one or more groups. Every tab in the ribbon contains a series of one or more groups. Groups are used to associate controls with similar functionality. Controls are the items that live inside the ribbon that users can interact with. In this we will be creating a tab, group and control as shown in the following







Prerequisites

  1. SharePoint Server 2010

  2. SharePoint development tools in Microsoft Visual Studio 2010


Create a SharePoint project:

  • Open Visual Studio 2010.On the File menu, go to New, and then click Project.

  • In Project Types, under Visual C#, select Empty SharePoint Project.









  • Enter CustomTab as the project name, and then click OK.

  • In the SharePoint Customization Wizard, select Deploy as a sandboxed solution, and then click Finish.












  • Right click on the solution, click on Add => New item.












  • Select Empty Element template and enter the name as CustomTab.










  • Click on Ok.

  • Open Elements.xml and replace the xml with the following

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

  2. <Elements xmlns="http://schemas.microsoft.com/sharepoint/">      

  3. <CustomAction Id="CustomRibbonTab" Location="CommandUI.Ribbon" RegistrationId="101" RegistrationType="List">             

  4. <CommandUIExtension>                    

  5. <CommandUIDefinitions>                          

  6. <CommandUIDefinition Location="Ribbon.Tabs._children">                                

  7. <Tab Id="Ribbon.CustomTab" Title="Custom Tab" Description="Custom Tab !!!" Sequence="501">                                        

  8. <Scaling Id="Ribbon.CustomTab.Scaling">                                               

  9. <MaxSize Id="Ribbon.CustomTab.MaxSize" GroupId="Ribbon.CustomTab.CustomGroup" Size="OneLargeTwoMedium"/>                                             

  10. <Scale Id="Ribbon.CustomTab.Scaling.CustomTabScaling" GroupId="Ribbon.CustomTab.CustomGroup" Size="OneLargeTwoMedium" />                                        

  11. </Scaling>                                        

  12. <Groups Id="Ribbon.CustomTab.Groups">                                               

  13. <Group Id="Ribbon.CustomTab.CustomGroup" Description="Custom Group!" Title="Custom Group" Sequence="52" Template="Ribbon.Templates.CustomTemplate">                                                      

  14. <ControlsId="Ribbon.CustomTab.CustomGroup.Controls">                                                            

  15. <Button Id="Ribbon.CustomTab.CustomGroup.CustomButton" Command="CustomTab.CustomButtonCommand" Sequence="15" Description="" LabelText="Custom Button" Image32by32="/_layouts/images/PPEOPLE.GIF" TemplateAlias="cust1"/>                                                                     

  16. </Controls>                                               

  17. </Group>                                        

  18. </Groups>                                 

  19. </Tab>                          

  20. </CommandUIDefinition>                          

  21. <CommandUIDefinition Location="Ribbon.Templates._children">                                 

  22. <GroupTemplate Id="Ribbon.Templates.CustomTemplate">                                      

  23. <Layout Title="OneLargeTwoMedium" LayoutTitle="OneLargeTwoMedium">                                               

  24. <Section Alignment="Top" Type="OneRow">                                                      

  25. <Row>                                                             

  26. <ControlRef DisplayMode="Large"TemplateAlias="cust1" />                                                      

  27. </Row>                                               

  28. </Section>                                                                                    

  29. </Layout>                                 

  30. </GroupTemplate>                          

  31. </CommandUIDefinition>                    

  32. </CommandUIDefinitions>                    

  33. <CommandUIHandlers>                       

  34. <CommandUIHandler Command="CustomTab.CustomButtonCommand" CommandAction="javascript:alert('Hello, world!');" />                          

  35. </CommandUIHandlers>

  36. </CommandUIExtension>   

  37. </CustomAction>

  38. </Elements>


Deploy the solution:

  1. Right click on the solution, then click on Build.

  2. Right click on the solution, then click on Deploy.

  3. Go to the SharePoint site => Document Library (In the Elements.xml file we have mentioned RegistrationId="101" the custom tab that we have created will be available only in the document library ).

  4. You could be able to see Custom Tab , Custom Group and the Custom Button as shown in the following


0 comments
bottom of page