Custom menu item with code behind

26/10/2012 12:39

Excellent article

https://www.codeproject.com/Articles/127421/SharePoint-2010-Site-Actions-Menu

 

xml version="1.0" encoding="utf-8"?>

<Elements xmlns="https://schemas.microsoft.com/sharepoint/">

<CustomAction

Id="MANSoftDev_SiteAction"

Sequence="1"

ControlClass="CustomActionMenuWithCode.CodeBehind.ApprovePages"

ControlAssembly="Aconcagua.Lukas.CustomActionMenuWithCode, Version=1.0.0.0,

Culture=neutral, PublicKeyToken=e6e2648ad6e25e0c"

Rights="ManageWeb"

Location="Microsoft.SharePoint.StandardMenu"

GroupId="SiteActions">

CustomAction>

Elements>

 

Code behind file

We need to add reference to System.Web, add assembly from output to safe controls in package

and set IncludeAssembly inPackage to false in project properties

 

using System.Web.UI.WebControls;

using Microsoft.SharePoint.WebControls;

namespace CustomActionMenuWithCode.CodeBehind

{

 

public class ApprovePages: WebControl

{

protected override void CreateChildControls()

{

SubMenuTemplate sub = new SubMenuTemplate();

sub.Text = "Custom Menu";

sub.Description = "Custom menu with submenu";

sub.ImageUrl = "/_layouts/Images/CustomActionMenuWithCode/piratIcon32.jpg";

sub.MenuGroupId = 90;

sub.Sequence = 100;

Controls.Add(sub);

 

MenuItemTemplate item = new MenuItemTemplate("SubMenu");

item.Description = "A submenu item";

item.ImageUrl = "/_layouts/images/settingsIcon.png";

sub.Controls.Add(item);

 

SubMenuTemplate sub2 = new SubMenuTemplate();

sub2.Text = "Custom Menu";

sub2.Description = "Custom menu with submenu";

sub2.ImageUrl = "/_layouts/images/settingsIcon.png";

sub.Controls.Add(sub2);

item = new MenuItemTemplate("SubMenu");

item.Description = "A submenu item";

item.ImageUrl = "/_layouts/images/settingsIcon.png";

sub2.Controls.Add(item);

}

}

}