Add custom SharePoint 2010, 2013 ribbon group,
tab, button and other controls: VB.NET, C#
Ribbon Designer Add-in Express Home > Ribbon Designer for SharePoint and Office 365 > Online Guide > Creating a custom SharePoint ribbon tab Creating a custom SharePoint ribbon tabThe sample project below demonstrates how you create the Ribbon UI of your SharePoint 2010, 2013 or SharePoint Online solution in Visual Studio 2010. A bit of theoryIn SharePoint Foundation terms, the Ribbon Designer is a feature. It provides a True RAD way for developing a custom Ribbon UI of your SharePoint solution. Using information provided at design-time, the Ribbon Designer creates a well-formed XML markup, which complies with the Server Ribbon scheme. Then, at a proper moment, the Ribbon Designer sends the XML to the server. Basing on the markup, the server creates the required Ribbon UI and connects it to the events - both server and client. Developing SharePoint projects requires that you have administrative permissions. In addition, if you have Windows Vista, Windows 7, or Windows 2008, it is imperative that you start Visual Studio 2010 via Run as Administrator. Adding the Ribbon DesignerYou have two options: Create a new SharePoint project:In Visual Studio, open the New Project dialog and navigate to the SharePoint folder in the Visual Basic or Visual C# branch depending on your preferred programming language. Select the Add-in Express SharePoint Ribbon item and click OK. This starts a one-step project wizard shown in the screenshot below: The project wizard requires that you specify a local site for debugging your solution. It allows you to choose the name of the feature enclosing the Ribbon Designer's functionality. Also, you must specify whether the solution will deploy to a server farm (default) or it will be a sandboxed solution. Clicking Finish creates and opens a new solution in the IDE. The solution contains just one project, a SharePoint project. We discuss it in Ribbon Designer basics. See also: Differences between sandboxed and farm solutions and Sandboxed solution considerations. Add the Ribbon Designer to an existing SharePoint project:You can add a Ribbon designer to an application page, user control or Visual Web part: just right-click the corresponding node in the Solution Explorer and choose the Add Ribbon Designer item. See also Integrating with existing SharePoint solutions. In the dialog, select ADX SharePoint Ribbon, enter a name in the Name text box and click Add. Ribbon Designer basicsFollowing the instructions above opens the Ribbon Designer in your project. The designer provides access to four areas:
Before we start looking at how to use these areas, let us find the Ribbon Designer files in your project. Ribbon Designer filesThe Ribbon Designer is a feature (in SharePoint Foundation terms). You specify the feature's name in the Add New Item dialog (see Adding the Ribbon Designer). The main file is called {feature name}.feature. In this sample, we name the feature SPRibbon, the resulting file name is SPRibbon.feature (see the screenshot). The feature provides three sections: designer, code and JavaScript code. To access them, you use the corresponding items of the context menu – just right-click the feature as shown in the screenshot. Ribbon tabs and controlsTo add a new tab to the Ribbon, you use the ADXSPRibbonTab command on the Ribbon Toolbox to add an AddinExpress.SharePoint.ADXSPRibbonTab component to the designer. Then, in the in-place visual designer, use tool buttons to add or delete the Ribbon components that form the Ribbon interface of your SharePoint 2010, 2013 or SharePoint Online project. To create the Ribbon UI shown in the screenshot above, change the caption of your tab to "My Ribbon Tab". Then, add a Ribbon group, and change its caption to "My Ribbon Group". Finally, select the group, add a button and set its caption to "My Ribbon Button". Use the ImageList and Image properties to set the image for the button; add an ImageList component onto the designer surface to provide images for your Ribbons. See also Ribbon controls in detail, Dealing with built-in Ribbon controls. Server-side eventsAdd an event handler to the OnAction event of the button and write the following code:
To handle the result, you add an event handler to the OnInitialize event (this is a JavaScript event) of the Ribbon Designer and write this code:
Client-side eventsNow, let's handle an event of a Ribbon control on the client side. You start with adding an event handler to the OnClick event of the Ribbon button created on the previous step. Now, write this JavaScript code:
That is, when required conditions are met, the event handler calls the Submit method. The parameters passed to the method are the "ProcessMessage" string (which is interpreted as an action's ID) and the message itself. If conditions are not met, the event handler prevents generation of a postback request. If the event handler for the OnAction event of the Ribbon Designer is supplied with the corresponding action ID, it invokes the ProcessMessage method as follows:
Debugging the projectFor instructions on debugging SharePoint projects, see Debugging SharePoint solutions. Deploying the Ribbon UIFor instructions on deploying SharePoint projects, see Packaging and deploying SharePoint solutions. The functionality of the Ribbon Designer is provided in AddinExpress.SharePoint.dll; you must deploy this file onto the target server. Deploying for Office 365The Ribbon Designer completely supports sandboxed solutions, so it can be deployed on an Office 365 web site. |