How to Create a Custom Ribbon button to Email an Item with Visual Studio in SharePoint 2010
This is a Step-by-Step tutorial about how to Create a Custom Ribbon button which will add a “E-mail a Link” button in View Items form that when clicked will open the default Email application with the link to this item.This example was posted by abigail brown at Creating a Custom Action by Using a Feature in our SharePoint forum.
The following steps create a custom action in Visual Studio 2010.
The procedures in this section assume a development environment where SharePoint 2010 is installed and configured, Microsoft Visual Studio 2010 is installed and the currently logged-in user has administrative rights on the SharePoint environment for deployment purposes.
To Create a Custom Action by Using a Feature
- In Visual Studio 2010, click New Project, expand the SharePoint node, click 2010, and then click Empty SharePoint Project. Name the project E-mail a Link and then click OK.
- In the SharePoint Customization Wizard, select the local SharePoint site that can be used for debugging and whether the solution will be deployed as a sandboxed or farm solution as shown in Figure 1.
- Click Finish.
Figure 1. Specify the deployment method
- In Solution Explorer, right-click the Features node and then click Add Feature as shown in
Figure 2. Add new feature
- Name the feature E-mail a Link and add a description as shown in Figure 3.
Figure 3. Name the feature
- In Solution Explorer, right-click the E-Mail a Link project, select Add, and then select New Item as shown in Figure 4.
Figure 4. Add a new item to the project
- In the Add New Item dialog box, select the Empty Element template, type E-Mail a Link as the name, and then click Add as shown in
Figure 5. Add an element to the project
- Open the Elements.xml file inside E-Mail a Link and then replace the file content with the following code example. If you like to apply this E-mail a Link to all the Lists, Change RegistrationsType From “ContentType” to “List” and RegistrationId from unique number to “101″
Description=”Email A Link”
Title=”Email A Link”
RegistrationId=”0×0100…(put actual Id here)”
<!– Define the (UI) button to be used for this custom action –>
LabelText=”E-mail a Link”
Description=”E-mail a Link”
<!– Define the action expected on the button click –>
<CustomAction Location=”ScriptLink” ScriptSrc=”/_layouts/xxxx/xxxx.js”/>
- Save the file.
- Add the E-Mail a Link element to the E-mail a Link feature as shown in Figure 6.
Add the E-Mail a Link element to the E-mail a Link
feature as shown in Figure 6.
- Right click the solution name and then click Deploy as shown in Figure 7. Visual Studio 2010 will build and deploy the solution to the farm.
Figure 7. Build and deploy the solution
- Navigate to the local site, Enable the feature E-mail a Link.
- Add custom and name it as Promotion list, and then Click on View Item. Observe the “E-mail a Link” under the Action Group as shown in Figure 8.
Figure 8. The E-mail a Link button
- Click the “E-mail a Link” button and notice the default Email application open with the link to this item.