Quantcast
Channel: SharePoint Development & Ops » SharePoint 2007
Viewing all articles
Browse latest Browse all 10

My Notes – Adding a Custom Action Menu Item

$
0
0

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"
   GroupId="SiteActions"
   Location="Microsoft.SharePoint.StandardMenu">
</CustomAction>

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" 
   Sequence="2"
   GroupId="SiteActions"
   Location="Microsoft.SharePoint.StandardMenu">
</CustomAction>

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";
 
Controls.Add(menuItem);

Viewing all articles
Browse latest Browse all 10

Latest Images

Trending Articles



Latest Images