There are some situations we need to have our own menu item to the context menu of the list. Its easy to add an entry to the context menu of any type of list. Depends on the type of list, menu type can be created. Each custom menu item is bounded to the custom action url. We can create a page and redirect it to that URL when an menu is clicked. Even add permission to the Menu item. Image can be added to the ImageUrl tag. basically menuitem is a CustomAction tag in the element xml. The custom action will be deployed as a feature to the site.
Custom Action Tags
The custom tag xml is the top level tag for adding the menu item. The Custom Action consist of minimally the following attributes
- Id – Unique Id to identify the Menu Item (Mandatory)
- RegistrationType – The type of list to which the menu item will be added, usually its the List
- RegistrationId – 100 for Custom list and 101 for doc lib.
- Location – Where the menu item needs to be added. it takes EditControlBlock, NewFormToolbar, DisplayFormToolbar, and EditFormToolbar
- Sequence – The sequence number where want to appear
- Title – Text for display
- ImageUrl – Icon image for the item
- Rights – Permission for the menu item. http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spbasepermissions.aspx
Below are the steps to be followed to create a Custom Menu in the List. The example shows how to create a menu for Custom List and Document Library.
Create a project using the Empty SharePoint Template. The Solution name is Senthamil.CustomItem
Create a New Item using Right Click Add->New Item and select Module and name the Module as MyCustomMenu
Once added the default sample.txt is added and contains modules.xml with element entry
Remove the sample file entry in the xml file
Remove the Module Tag and add the CustomAction node with the details for creation of Menuitem. Add the below code under the Elements Node
The above code i have created two menuitem. Also the URL is redirected to the custom page which is created in the site. The first customaction is for Custom List and the Second customaction is for Document library. The second menu item will be visible to whom who have access to Add item.
The above shows the feature view which will be deployed in the site.
Now the code is able to deploy. On the Solution properties Debug tab add the URL to be deployed. Once added the URL u can directly deploy the feature to the Site. Right click the solution and Select Deploy to deploy the feature. Once successfully deployed the feature will be activated and can see in the List and document library.
Now when deployed i can see the custom menu in the Custom List called Animal.
In the document library can see the domain option custom url.