Adding a custom menu item to the NewMenu


Table of Contents

The following article includes samples that will demonstrate how to add a custom menu item to the NewMenu of a SharePoint document library. Unable to render embedded object: File (Custom_Menu_Item_on_the_New_menu_drop-down.png) not found.

elements.xml Contents

<?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
	<CustomAction GroupId="NewMenu"
				  Location="Microsoft.SharePoint.StandardMenu"
				  ControlAssembly="NewMenuSample, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9860eb6
				  ControlClass="NewMenuSample.SampleMenuItem"
				  RegistrationId="101"
				  RegistrationType="List">
	</CustomAction>
</Elements>

SampleMenuItem.cs Contents

using System;
using System.Web.UI.WebControls;
using Microsoft.SharePoint.WebControls;

namespace NewMenuSample
{
	public class SampleMenuItem : WebControl
	{
		protected override void CreateChildControls()
		{
			MenuItemTemplate menu = new MenuItemTemplate();
			menu.ID = "SampleMenu";
			menu.Text = "Menu Item 1";
			menu.Description = "Menu Item 1 Description";
			this.Controls.Add(menu);
		}
	
		protected override void Render(System.Web.UI.HtmlTextWriter writer)
		{
			RenderChildren(writer);
		}
	}
}

Known Issues

It is important that include the override of Render if this menu item control is going to be located on the NewMenu. Because of the CSS that is applied to NewMenu controls, they are wrapped in a tag which causes the control to render as blank on the menu. If you include the RenderChildren method in the override of Render, this will resolve this issue. Another known issue is that if you create sub-menu items that will exist on the NewMenu it will cause a strange flickering behavior. The solution is to include the fixup.js file provided by Pascal Van Vlaenderen in your project.

External Links

Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.



Creative Commons License
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License. Hosted generously by CustomWare