Sample CustomActions for SharePoint

Search

Accessible SharePoint WebSites
Download ARF

Sample CustomActions for SharePoint

http://blog.thekid.me.uk

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 view...one 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="http://schemas.microsoft.com/sharepoint/">

    <CustomAction

        Id="TheKid.DuplicateListItem"

        Location="EditControlBlock"

        Title="Copy Item..."

        RegistrationType="ContentType"

        RegistrationId="0x01">

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

    </CustomAction>

    <CustomAction

        Id="TheKid.ClearListItems"

        Location="Microsoft.SharePoint.StandardMenu"

        GroupId="ActionsMenu"

        Title="Delete All Items"

        RegistrationType="List"

        Sequence="10">

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

    </CustomAction>

</Elements>

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.

Posted by Vincent Rothwell on Saturday, 23 Jun 2007 17:39  - 79 Comments
Orininally printed from http://thekid.me.uk - Copyright Vincent Rothwell 2007
 

Comments

Sunday, 27 Jul 2008 10:36 by Chris White
Hi Vince, Have you found a way to make the sequence attribute work correctly for a customaction you add to the actions menu ? No matter what value I set the sequence attribute to be, the new item on the Actions menu always seems to appear at the bottom of the menu ?? Thanks in advance. Chris.

Sunday, 27 Jul 2008 10:36 by Daniel
Hey, many thanks for this great article

Sunday, 27 Jul 2008 10:36 by Nicolas
Hello, Thanks for the tips but it add this action to all list of the site. How to add a custom item in the "Actions" menu for a custom list only ? Thanks in advance.

Sunday, 27 Jul 2008 10:36 by Vince
Nicolas, Good question, not sure you can using this method. Your choices are by FileType, ContentType or List template ID. To achieve what you want it would be best to create a feature for your list, which has a pre-defined template ID. You can then use this as the RegistrationId to only show the additional menu for a list created from that template. There is another way, using javascript, which is not so elegant as a list feature, but will work with different custom lists and will give the decision to you as to when to add it. These articles could help... http://blog.thekid.me.uk/archive/2007/07/22/easily-print-sharepoint-lists-using-your-own-template.aspx http://blogs.msdn.com/bowerm/articles/175691.aspx http://www.helloitsliam.com/archive/2007/07/24/moss2007-–-item-level-menus-using-“editcontrolblock”.aspx They both add to the ECB menu using javascript. I plan to do an article on this soon, probably next week.

Sunday, 27 Jul 2008 10:36 by zhihao
I have question about custom action. If you apply a custom action to document library, you will find that the custom action will display for both document item and document folder. So how to only apply custom action for document item?

Sunday, 27 Jul 2008 10:36 by zhihao
I have question about custom action. If you apply a custom action to document library, you will find that the custom action will display for both document item and document folder. So how to only apply custom action for document item?

Sunday, 27 Jul 2008 10:36 by dtnrl ltxvkjdo
vdrmybpoc nvkwpzih zchnlaefs hgodxjer yqowkeacu caujfbv thbney

Sunday, 27 Jul 2008 10:37 by Isoz
Great Tool for people in companies having to type a lot of datas ;-)

Sunday, 27 Jul 2008 10:37 by Tiiu
Hi Vince, When attempting to install the WSP, I get the following error: thekid.listactions.wsp: The file manifest.xml appears invalid. Any help would be appreciated.

Sunday, 27 Jul 2008 10:37 by Tiiu
Hi Vince, When attempting to install the WSP, I get the following error: thekid.listactions.wsp: The file manifest.xml appears invalid. Any help would be appreciated.

Sunday, 27 Jul 2008 10:37 by Tiiu
Hi Vince, When attempting to install the WSP, I get the following error: thekid.listactions.wsp: The file manifest.xml appears invalid. Any help would be appreciated.

Sunday, 27 Jul 2008 10:37 by Ajit
I want to know if i want to place a button on the list view toolbar then does this concept of ECB Menu will help me or there is another way of achieving this.

Sunday, 27 Jul 2008 10:37 by Vince
Ajit, Yes a similar concept...have a look at this http://msdn2.microsoft.com/en-us/library/ms473643.aspx

Sunday, 27 Jul 2008 10:37 by Morten
Hello Really nice article did the work for me. However I have an additional question. The standard ECB items such a delete have an confirmation box ex. "Do you want to delete this item?" how do I add this to my new ECB item?

Sunday, 27 Jul 2008 10:37 by Jatuphum
Hello, I have some problem about menu toolbar. But my toolbar is on "Form Library", not "Document Library". I try to customize Feature.xml and Elements.xml for removing "Upload" and "Actions" menu from Toolbar Library. At first I found my form library physical feature folder on SharePoint Server. I found Feature.xml and Elements.xml in it. I think Feature.xml is not necessary to edit because it is refer to default Elements.xml. Bellow: &lt ElementManifest Location="Elements.xml" / &gt Then I opened Elements.xml to edit. I try to remove "Upload" Menu by added &lt HideCustomAction Id="HideUploadDoc" GroupId="UploadMenu" HideActionId="UploadMenu" Location="Microsoft.SharePoint.StandardMenu"/ &gt in Elements section. Then I reset IIS. But "Upload" menu is still existing. Please help me. I spend my a lot of time to remove it but it still does not work. Thank you very much.

Friday, 15 Aug 2008 02:51 by zeeshan
Hay i downloaded the full project when i run the project i got the command error of XCopy in visual studio can you please guide me how to use your sample code how to use WSP file. As i have no idea

Thursday, 2 Oct 2008 09:07 by Rick
thnx for posting this topic. I have a question about the CustomAction. I'll see the menu item added correctly, but i couldn't see it at the right screen at Manage content and structure, only at the list page (for example /List/News/AllItems.aspx). Does anyone know how i could change the menu item at the right screen of Manage content and structure? Thank you very much.

Tuesday, 14 Oct 2008 09:45 by Resel
Hello all. I've the same problem as mentioned above in the Post on Sunday, 27 Jul 2008 10:37 by Jatuphum. I've tried to remove am MenuItem from the EditContolBlock - by a Feature with HideCustomAction. The Custom Item Menu is by default with a site-scoped feature and should be removed by a web-scoped feature on some few webs... Part of Adding Feature's CustomAction.xml: ------------- <CustomAction Id="IdNameOfMyMenuItem" Location="EditControlBlock" Title=">>Text of my Menu.." ImageUrl="~site/_layouts/images/sendotherloc.gif" Sequence="1" RegistrationType="ContentType" RegistrationId="0x01"> <UrlAction Url="~site/_layouts/SpecialActionsXY/MySpecialActionXY.aspx?List={ListId}&amp;ID={ItemId}"/> </CustomAction> ------------- Part of Removing Feature's CustomAction.xml: ------------- <HideCustomAction Id="Hide.IdNameOfMyMenuItem" HideActionId="IdNameOfMyMenuItem" Location="EditControlBlock"/> ------------- => but it does not work... the EditControlBlock Item is not removed. (with an item in the Location "Microsoft.SharePoint.StandardMenu" it works, the Menuitem is removed!!) Any Ideas by anyone? Can anyoune Help me? Has anyone ever removed a MenuItem in the EditControlBlock? thx

Thursday, 16 Oct 2008 04:38 by PrashanthSpark
I have question about custom action. If you apply a custom action to document library, you will find that the custom action will display for both document item and document folder. So how to only apply custom action for document item? Any help Please : )

Saturday, 1 Nov 2008 03:10 by kreditrechner
i downloaded the full project when i run the project i got the command error of XCopy in visual studio can you please guide me how to use your sample code how to use WSP file. As i have no idea

Tuesday, 11 Nov 2008 11:45 by Gary Newman
This worked great!! I installed the feature and worked flawless! Thank you for sharing the code.

Wednesday, 26 Nov 2008 11:34 by rüya tabiri
Thank You...

Sunday, 30 Nov 2008 07:10 by Paul Noone
Hi Vince, The Delete All Items action works great. In fact it works too well! I was expecting some kind of confirmation, or at least to find the items in the user recycle bin. But it seems the item is completely removed and not retriavable. Is there a way to customise the script so items are at least deleted to the administrator recycle bin? With regards tot he Copy Item ACB command I receive the following error. Any advice appreciated. -- To add an item to a document library, use SPFileCollection.Add() at Microsoft.SharePoint.SPListItem.PrepareItemForUpdate(Guid newGuidOnAdd, Boolean bMigration, Boolean& bAdd, Boolean& bPublish, Object& objAttachmentNames, Object& objAttachmentContents, Int32& parentFolderId) at Microsoft.SharePoint.SPListItem.UpdateInternal(Boolean bSystem, Boolean bPreserveItemVersion, Guid newGuidOnAdd, Boolean bMigration, Boolean bPublish, Boolean bNoVersion, Boolean bCheckOut, Boolean bCheckin, Boolean suppressAfterEvents) at Microsoft.SharePoint.SPListItem.Update() at ASP._layouts_ceocustom_copylistitemecb_aspx.__Render__control1(HtmlTextWriter __w, Control parameterContainer) in c:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE\LAYOUTS\TheKid\CopyListItem.aspx:line 36 at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) at System.Web.UI.Page.Render(HtmlTextWriter writer) at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

Saturday, 3 Jan 2009 09:18 by oyun
thank you::))

Sunday, 4 Jan 2009 05:21 by Chat
thanks

Monday, 19 Jan 2009 02:56 by siudy
I use this configuration to do not display menu item on the document library folder: <CustomAction RegistrationId="0x0101" RegistrationType="ContentType" ... But how to use ControlAssembly and ControlClass section to work with the document library's items? I always get the empty item in the context menu and the "Invalid Page url" message after click.

Wednesday, 4 Feb 2009 07:49 by kv
Hi, experiencing the same issue as siudy.

Sunday, 8 Feb 2009 11:25 by Naveen
How would I restrict ECB menu item to a specific list? Any quick help would be greatly appreciated.

Thursday, 26 Feb 2009 11:03 by vikpri
Hi, Thanks for the article.It was very helpful. Can you please tell me how can I add "Separators" between menu items throught custom action xml.I had a look at the custom elements provided for action xml,but could not an attribute fo separators.

Tuesday, 3 Mar 2009 04:33 by Gary
How can I change the default action to custom action?

Thursday, 5 Mar 2009 08:53 by sohbet odalari
thank you very much

Saturday, 7 Mar 2009 02:15 by güzel sözler
thank you :)

Saturday, 7 Mar 2009 03:10 by Sohbet
thankss

Friday, 13 Mar 2009 03:41 by Chat
thank youu

Wednesday, 18 Mar 2009 12:13 by Ligtv izle
thank you cano

Monday, 23 Mar 2009 06:31 by Mynet
thank you kankamm

Tuesday, 24 Mar 2009 04:56 by Sarki dinle
seoking ft erkan

Saturday, 28 Mar 2009 04:59 by Maç izle
thankk

Thursday, 2 Apr 2009 06:38 by Chris
Hi Vince, I got the same error as mentioned by someone else. Is there a fix? When attempting to install the WSP, I get the following error: thekid.listactions.wsp: The file manifest.xml appears invalid. Any help would be appreciated.

Monday, 6 Apr 2009 04:03 by ligtv izle
you are my desire..

Sunday, 12 Apr 2009 12:17 by chat
thank you turkish chat34 !

Wednesday, 15 Apr 2009 01:14 by Manish
Hello I have written a blog explaning "How to : Custom action specific to List" Let me know if it's Useful. http://mnish.blogspot.com/2009/04/create-custom-action-specific-to-list.html regards Manish

Thursday, 16 Apr 2009 10:39 by Rich Browne
vikpri: If you want to add a menu separator, you can only do this in code (you can't do it in caml alone). The process is: 1. Create a new CustomAction inside your feature elements file, specifying the ControlAssembly and ControlClass properties: <CustomAction Id="{7DFBDA0C-D982-4219-AAF6-3C76309DF31B}" Location="Microsoft.SharePoint.StandardMenu" GroupId="SiteActions" ControlAssembly="MyCustomActions" ControlClass="MyCustomActions.TestAction"> </CustomAction> 2. Create the 'TestAction' class, inheriting the 'Microsoft.SharePoint.WebControls.WebControl' class 3. Override the CreateChildControls() method and put the following code in it: MenuSeparatorTemplate separator = new MenuSeparatorTemplate(); Controls.Add(separator); 4. Sign the assembly, compile and gac it, then copy your feature files to the 12 hive. 5. Reset IIS and browse to your site. 6. Enable the feature and you'll now have a seperator at the bottom of your site actions menu. It may not be obvious until you put another custom action underneath it though :)

Saturday, 18 Apr 2009 12:02 by ligtv izle
thank you

Sunday, 3 May 2009 09:38 by sohbet
thanks

Monday, 4 May 2009 06:23 by justin tv
turkish justin tv..

Friday, 22 May 2009 08:03 by lig tv izle
thank you

Wednesday, 8 Jul 2009 09:29 by islami chat
thank you very much my friends..

Friday, 10 Jul 2009 11:39 by Laura Northrup
yHDSFZ Thanks for your insights � I couldn�t agree more.,

Monday, 13 Jul 2009 12:09 by dennis conrad
ZcJP5i Hi! The post is really interesting! I�ve read your blog and can say it�s a good job.thanks,

Monday, 13 Jul 2009 12:10 by Jon Sharp
Oh hell yeah� no graphical smilies around here.,

Monday, 13 Jul 2009 12:11 by Aaron Wanstrath
Thanks for your insights � I couldn�t agree more.,

Tuesday, 14 Jul 2009 02:13 by Robert Oetjen
6hvVGp Thanks for your insights � I couldn�t agree more.,

Friday, 24 Jul 2009 05:47 by etiket
Thansk for this post, i can not found this anywhere

Thursday, 30 Jul 2009 12:59 by Jeff Elkins
Good Thank you It�s very beautifully,

Thursday, 30 Jul 2009 01:00 by Matthew Berzonsky
Very interesting!I�d like to see how far he goes and how well the word will get out.,

Thursday, 30 Jul 2009 01:00 by DeJuan Traylor
Thanks for your insights � I couldn�t agree more.,

Thursday, 30 Jul 2009 01:00 by Pam Moshier
Thanks for your insights � I couldn�t agree more.,

Thursday, 30 Jul 2009 01:00 by Terry Rude
Oh hell yeah� no graphical smilies around here.,

Thursday, 30 Jul 2009 01:00 by ron machniak
Thanks I�ll give that a go!,

Thursday, 30 Jul 2009 01:01 by Thomas Scherrer
Don�t you think he is a little late for the game?,

Thursday, 30 Jul 2009 01:01 by Jeff Delmore
Good Thank you It�s very beautifully,

Thursday, 30 Jul 2009 01:01 by Phyllis Kokoropoulos
nice job, very thanks�,

Thursday, 30 Jul 2009 01:02 by Tyler Strickler
Thanks for your insights � I couldn�t agree more.,

Friday, 31 Jul 2009 01:22 by Wayne Vreatt
Good Thank you It�s very beautifully,

Thursday, 6 Aug 2009 09:43 by Seamus
SAFARI Browser...Please help!! Below works for IE and firefox but for safari for windows the 2nd query string value will not work because safari renders the &amp as "&amp;" instead of "&" I tried using &#38 but this dis not work either....Any ideas? <UrlAction Url="~site/_layouts/SpecialActionsXY/MySpecialActionXY.aspx?List={ListId}&amp;ID={ItemId}"/>

Saturday, 8 Aug 2009 06:31 by dLhgHiWUb
tr2.txt;20;50

Saturday, 8 Aug 2009 06:31 by WGirTabx
tr2.txt;20;50

Thursday, 27 Aug 2009 07:23 by Amith
Hey Guys, I completely agree with this approach. My Question is some thing else .... Can we get a similar item in the (custom action) in the ECB or Toolbar in sitemanager.aspx in Layouts folder ? If you have any idea please revert back to be ;-) Regards Amith Sasi

Thursday, 3 Sep 2009 06:52 by betsson309
Thanks for the nice content of information.

Friday, 11 Sep 2009 10:49 by Sravan Kasyap Karanam
Hi, great article. I had a small question, when we click on the 'Copy Item..' menu item, does it redirect to another aspx page specified in the url? if it does, how do i restrict it not to redirect to a different page and copy an item behind the scenes just on the click of that menu item? Please help me as i am totally stuck. You can also email me at sravankasyapk@gmail.com. Regards, Sravan Kasyap Karanam

Friday, 11 Sep 2009 11:55 by Sravan Kasyap Karanam
Hi, great article. I had a small question, when we click on the 'Copy Item..' menu item, does it redirect to another aspx page specified in the url? if it does, how do i restrict it not to redirect to a different page and copy an item behind the scenes just on the click of that menu item? Please help me as i am totally stuck. You can also email me at sravankasyapk@gmail.com. Regards, Sravan Kasyap Karanam

Wednesday, 16 Sep 2009 05:51 by Betsson409
I had a small question, when we click on the 'Copy Item..' menu item, does it redirect to another aspx page

Friday, 9 Oct 2009 07:08 by chat
chat rooms turkish thank you very much..

Thursday, 22 Oct 2009 10:14 by alwa7ish
Dear, I tried the above feature and it didnt work on the picture library while it worked properly on document libraries and other list. Any advise. Your help is much appreciated. Thanks

Tuesday, 27 Oct 2009 03:18 by Radhi
SAFARI Browser...Please help!! Below works for IE and firefox but for safari for windows the 2nd query string value will not work because safari renders the &amp as "&amp;" instead of "&" I tried using &#38 but this dis not work either....Any ideas? <UrlAction Url="~site/_layouts/SpecialActionsXY/MySpecialActionXY.aspx?List={ListId}&amp;ID={ItemId}"/>

Thursday, 29 Oct 2009 05:48 by cainos
Tahnks very informative.

Sunday, 22 Nov 2009 10:25 by konya chat
konya sohbet

Tuesday, 24 Nov 2009 10:37 by pratap
Hey, Great article. I would like to add/hide menu items to ACTIONS toolbar menu in SITEMANAGER.ASPX. Any Ideas? Thanks



Url

Email

Comments