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.
For More Info : http://msdn.microsoft.com/en-us/library/ms473643.aspx
Using SharePoint Designer 2010
Following are the steps to create custom action menu.- Open SharePoint designer 2010 and open the site in which you want to make the changes.
- Select list and select list setting tab as shown below.
- Click on Custom Actions Button on ribbon and select the List Item Menu.
- Enter the Name, Description and URL in create custom action window as shown below .
- 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 |
03 | private void CutomActionFromClientObjectModel() |
04 |
05 | { |
06 |
07 | using (Microsoft.SharePoint.Client.ClientContext datacontext = new Microsoft.SharePoint.Client.ClientContext( "http://mossportal/" )) |
08 |
09 | { |
10 |
11 | Microsoft.SharePoint.Client.List list = datacontext.Web.Lists.GetByTitle( "Employees" ); |
12 |
13 | Microsoft.SharePoint.Client.UserCustomActionCollection customactioncollection = list.UserCustomActions; |
14 |
15 | Microsoft.SharePoint.Client.UserCustomAction customaction = customactioncollection.Add(); |
16 |
17 | customaction.Title = "View Client Object Model" ; |
18 |
19 | customaction.Name = "My Attendance" ; |
20 |
21 | customaction.Sequence = 10; |
22 |
23 | customaction.Location = "EditControlBlock" ; |
24 |
25 | customaction.Url = "http://mossportal/_layouts/empatnd.aspx?ItemId={ItemId}" ; |
26 |
27 | customaction.Update(); |
28 |
29 | datacontext.Load(list, lst => lst.UserCustomActions); |
30 |
31 | datacontext.ExecuteQuery(); |
32 |
33 | } |
34 |
35 | } |
Server Object Model
01 | //CUSTOM ACTIONS MENU USING SHAREPOINT CLIENT OBJECT MODE |
02 |
03 | private void CutomActionFromServerObjectModel() |
04 |
05 | { |
06 |
07 | //CUSTOM ACTIONS MENU USING SHAREPOINT SERVER OBJECT MODE |
08 |
09 | using (SPSite site = new SPSite( "http://mossportal/" )) |
10 |
11 | { |
12 |
13 | using (SPWeb web = site.OpenWeb()) |
14 |
15 | { |
16 |
17 | SPList list = web.Lists.TryGetList( "Employees" ); |
18 |
19 | SPUserCustomActionCollection actioncollection = list.UserCustomActions; |
20 |
21 | SPUserCustomAction actions = actioncollection.Add(); |
22 |
23 | actions.Title = "View Server Object Model Demo" ; |
24 |
25 | actions.Name = "My Attendance" ; |
26 |
27 | actions.Sequence = 10; |
28 |
29 | actions.Location = "EditControlBlock" ; |
30 |
31 | actions.Url = "http://mossportal/_layouts/empatnd.aspx?ItemId={ItemId}" ; |
32 |
33 | actions.Update(); |
34 |
35 | } |
36 |
37 | } |
38 |
39 | } |
Using Custom Site Definition
01 | <!--?xml version= "1.0" encoding= "utf-8" ?--> |
02 |
03 | <elements xmlns= "http://schemas.microsoft.com/sharepoint/" > |
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 |
11 | <urlaction url= "http://mossportal/_layouts/empatnd.aspx?ItemId={ItemId}" > |
12 |
13 | </urlaction></customaction> |
14 |
15 | </listtemplate></elements> |
Happy SharePointing!!!!!!!!!!
Comments