Adding a custom menu item to the NewMenu

From WSSWiki

Jump to: navigation, search
Custom Menu Item on the New menu drop-down
Custom Menu Item on the New menu drop-down

The following article includes samples that will demonstrate how to add a custom menu item to the NewMenu of a SharePoint document library.

Contents

[edit] feature.xml Contents

<?xml version="1.0" encoding="utf-8" ?>
<Feature xmlns="http://schemas.microsoft.com/sharepoint/"
         Id="F1CF56A1-1410-47A1-8647-6B90084C1021"
         Title="Sample NewMenu"
         Description="This is a feature showing how to add custom menu to the NewMenu."
         Scope="Web"
         Hidden="False"
         Version="1.0.0.0">
	<ElementManifests>
		<ElementManifest Location="elements.xml" />
	</ElementManifests>

</Feature>

[edit] 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=9860eb616e81cf1b"
		 ControlClass="NewMenuSample.SampleMenuItem"
		 RegistrationId="101"
		 RegistrationType="List">
   </CustomAction>
</Elements>

[edit] 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);
        }
    }
}

[edit] 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.

[edit] External Links

Personal tools