Friday, July 13, 2012

Separator in CustomAction for EditControlBlock

I thought I was assigned the easiest of tasks: Add a separator between our custom action and the other menu items.

I had this custom action in the ECB-menu for documents that was working perfectly. All I had to do was to add a separator. How hard could it be? Well... Apparently Microsoft has left out the possibility to add separators in the custom action xml, http://msdn.microsoft.com/en-us/library/ms460194.aspx. The only possibility to add a separator is to create it code behind with a MenuSeparatorTemplate, http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.webcontrols.menuseparatortemplate.aspx. This would have been all fine and dandy if code behind was an option for ECB-menus, but it isn't allowed. You can only attach UrlAction to ECB-menus.

There is a solution where you can add a separator by changing core.js, http://weblogs.asp.net/jan/archive/2009/09/03/customizing-the-sharepoint-ecb-with-javascript-part-1.aspx, but this isn't a viable option for me. The only really doable solution I found was to add our custom action dead last in the ECB-menu by setting Sequence="2000" since the delete option apparently adds a separator after itself. I found this out just by coincidence.

Here is my CustomAction element:

  <CustomAction
    Id="SharePoint.Paradise.CustomAction.DoStuff"
    Location="EditControlBlock"
    Title="Do stuff"
    RegistrationType="ContentType"
    RegistrationId="0x0101"
    Sequence="2000">
    <UrlAction Url="javascript:alert('Hello World!');"/>
  </CustomAction>

This is how it turned out in SharePoint:



Yet another day in SharePoint paradise...

1 comment:

  1. Hello! I stumbled across this post while researching CustomAction options for EditControlBlock versus what I had been doing with javascript. In WSS and 2007, and 2010, I used javascript code to add items to the ECB as outlined at: http://spevilgenius.blogspot.com/2011/05/creating-custom-edit-control-block-ecb.html

    Not sure if its helpful or not but thought I would point it out.

    ReplyDelete