June 11, 2012

Creating a Custom Action by Using a Feature

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.
    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.
    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"
    1. <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
      Description="Email A Link"
      Title="Email A Link"
      RegistrationId="0x0100...(put actual Id here)"
    <CommandUIExtension xmlns="http://schemas.microsoft.com/sharepoint/">
    <!-- Define the (UI) button to be used for this custom action -->

    <CommandUIDefinition Location="Ribbon.ListForm.Display.Actions.Controls._children">
    <Button Id="{B511A716-54FF-4EAE-9CBE-EA02B51B626E}"
    Image16by16Top="-16" Image16by16Left="-88"
    LabelText="E-mail a Link"
    Description="E-mail a Link"
    <!-- Define the action expected on the button click -->
    <CommandUIHandler Command="{4E2F5DC0-FE2C-4466-BB2D-3ED0D1917763}" CommandAction="javascript:mailThisPage();" />
    <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.
If you have any questions you can reach out our SharePoint Consulting team here.

No comments:

Post a Comment