Diffrent ways to deploy Custom Action menu in SharePoint 2010

 Previously we need to create a custom List Definition in order to create a custom action menu for a specific whether it for Actions menu or ECB Menu. Now with SharePoint 2010 we can create custom actions for specific list in many ways.

Using SharePoint Designer 2010

Following are the steps to create custom action menu.
  1. Open SharePoint designer 2010 and open the site in which you want to make the changes.
  2. Select list and select list setting tab as shown below.
  3. Click on Custom Actions Button on ribbon and select the List Item Menu.
Or you can choose from custom action section shown below. This will create a Menu for the List Item(EditControlBlock).
  1. Enter the Name, Description and URL in create custom action window as shown below .


  1. Once done with this, click save and navigate to list in SharePoint.

Using Object Model


Client Object Model

01//CUSTOM ACTIONS MENU USING SHAREPOINT CLIENT OBJECT MODE
02 
03private void CutomActionFromClientObjectModel()
04 
05{
06 
07using (Microsoft.SharePoint.Client.ClientContext datacontext = new Microsoft.SharePoint.Client.ClientContext("http://mossportal/"))
08 
09{
10 
11Microsoft.SharePoint.Client.List list = datacontext.Web.Lists.GetByTitle("Employees");
12 
13Microsoft.SharePoint.Client.UserCustomActionCollection customactioncollection = list.UserCustomActions;
14 
15Microsoft.SharePoint.Client.UserCustomAction customaction = customactioncollection.Add();
16 
17customaction.Title = "View Client Object Model";
18 
19customaction.Name = "My Attendance";
20 
21customaction.Sequence = 10;
22 
23customaction.Location = "EditControlBlock";
24 
25customaction.Url = "http://mossportal/_layouts/empatnd.aspx?ItemId={ItemId}";
26 
27customaction.Update();
28 
29datacontext.Load(list, lst => lst.UserCustomActions);
30 
31datacontext.ExecuteQuery();
32 
33}
34 
35}

Server Object Model

01//CUSTOM ACTIONS MENU USING SHAREPOINT CLIENT OBJECT MODE
02 
03private void CutomActionFromServerObjectModel()
04 
05{
06 
07//CUSTOM ACTIONS MENU USING SHAREPOINT SERVER OBJECT MODE
08 
09using (SPSite site = new SPSite("http://mossportal/"))
10 
11{
12 
13using (SPWeb web = site.OpenWeb())
14 
15{
16 
17SPList list = web.Lists.TryGetList("Employees");
18 
19SPUserCustomActionCollection actioncollection = list.UserCustomActions;
20 
21SPUserCustomAction actions = actioncollection.Add();
22 
23actions.Title = "View Server Object Model Demo";
24 
25actions.Name = "My Attendance";
26 
27actions.Sequence = 10;
28 
29actions.Location = "EditControlBlock";
30 
32 
33actions.Update();
34 
35}
36 
37}
38 
39}

Using Custom Site Definition

01<!--?xml version="1.0" encoding="utf-8"?-->
02 
04 
05<!-- Do not change the value of the Name attribute below. If it does not match the folder name of the List Definition project item, an error will occur when the project is run. -->
06 
07<listtemplate name="Employee" type="10008" basetype="0" onquicklaunch="TRUE" allowdeletion="FALSE" disableattachments="TRUE" default="TRUE" securitybits="11" sequence="410" rootwebonly="TRUE" displayname="Employees" description="Employees" image="/_layouts/images/itgen.png" hidden="TRUE">
08 
09<customaction id="Employee" location="EditControlBlock" title="View Attendance" description="Click here to view attendance." registrationtype="List" registrationid="10008" sequence="10">
10 
12 
13</urlaction></customaction>
14 
15</listtemplate></elements>
For More Info : http://msdn.microsoft.com/en-us/library/ms473643.aspx 

Happy SharePointing!!!!!!!!!!

Comments