My Notes – Adding a Custom Action Menu Item

This post is really about documenting a really trivial, and often blogged about, feature within SharePoint: adding custom actions to the Site Actions menu.

Why another post? Simply because, for me, the final solution to my particular problem involved the amalgamation of a couple different posts. Six months down the road, this becomes difficult to track down or recreate, so I like to document the entire experience, what worked, what didn’t. If anyone is not clear on a piece of it, let’s discuss in the comments.

Scenario: I’d like to add a custom action menu item to the Site Actions menu, positioned below the New Document Library link.

The code to achieve something like this, with or without the CKSDev Toolkit looks something like:

<CustomAction Id="{AF969C2D-A5B7-4A59-B3C8-4B888A81A8DF}" 
   Title="New Menu Item"

The above works well, and will add a new entry to the Site Actions menu, however, it doesn’t allow you to position the new menu item. Looking into the available properties, I figured that the Sequence property would do the trick, as follows:

<CustomAction Id="{AF969C2D-A5B7-4A59-B3C8-4B888A81A8DF}" 
   Title="New Menu Item" 

However, others have pointed out that this does not work for all menu items, just any custom ones you’ve created. So you’re only setting a sequence for the custom actions.

So how do we get around this? Well, you’ll want to use a receiver as outlined in the post above. No need to repeat here, because Gilles Lauwers does a good job of outlining what you need to do.

When all is said and done, my method looks something like:

MenuItemTemplate menuItem = new MenuItemTemplate();
menuItem.Text = "New Link";
menuItem.ImageUrl = "/_layouts/images/myimage.png";
menuItem.Description = "Creates a standard link.";
menuItem.MenuGroupId = 200;
menuItem.Sequence = 221;
SPWeb web = SPContext.Current.Web;
menuItem.ClientOnClickNavigateUrl = web.Url + "/_layouts/settings.aspx";

UPDATE: As per venkat’s comment below, the file in question is the Elements.xml file, see below for some screenshots of what this looks like.

Screen Shot 2014-04-28 at 10.33.41 AM

Screen Shot 2014-04-28 at 10.34.04 AM

2 Responses to “My Notes – Adding a Custom Action Menu Item”

  1. venkat April 1, 2014 at 5:31 am #

    It is nice but the above code which file we want to write . please mention file name also like element.xml

  2. Shereen Qumsieh April 28, 2014 at 5:36 pm #

    Thank you venkat for the feedback, I’ve updated my post. Does that help?

Leave a Reply