Thursday, July 15, 2010

Sample CustomActions for SharePoint !

SharePoint gives a lot of opportunities to customize the user interface and add your own customizations. There are a lot of examples of modifying the 'EditControlBlock', the drop down actions list shown on list items in a list view, and adding custom functionality to the 'Actions' menu of the list view.

I thought I would add my own to the mix, with a couple of samples which I have found useful in testing recently. The sample project adds two items to a list to the 'EditControlBlock', which allows you to make a copy of the selected list item and another which adds an items to the Actions menu, which allows you to delete all the items in the current list.

image image

Adding the items is done via a feature and some custom actions. The actions are just pointers to .aspx pages in the _layouts folder and these pages actually perform the copying and deletion of SPListItems.

<Elements xmlns="">




        Title="Copy Item..."



        <UrlAction Url="~site/_layouts/TheKidListActions/CopyListItem.aspx?List={ListId}&amp;ID={ItemId}"/>  






        Title="Delete All Items"



        <UrlAction Url="~site/_layouts/TheKidListActions/ClearList.aspx?List={ListId}"/>



Note the query string parameters which have tokens representing various values you may need to use in your .aspx page. Here I use ListId and ItemID...the other two possibilities are ItemUrl and SiteUrl.

It is also worth noting the RegistrationType of the copy item CustomAction. This you can see is registering itself by content type and is using a RegistrationId of 0x01. This will register it for all lists in SharePoint. For more details of how SharePoint decides which items appear in the EditControlBlock you should have a look at the CORE.JS file in SharePoint. The CORE.JS file contains a function called InsertFeatureMenuItems which decides which items will be displayed in the menu for each item in the list.

The functionality for the two actions are completely contained within the .aspx pages and the project contains no DLLs and only installs the .aspx pages. To modify the functionality simply open the .aspx and change the code.

You can also use code to create the Custom Action URL.

You can download the WSP to install, or you can download the full source for the project.

UPDATE: I have another article which shows how to use code to achieve similar results.

No comments:

Post a Comment