Tuesday, April 08, 2008

EditControlBlock registrationtypes

Been working on adding a new item to the SharePoint drop down menus...easy to do by creating a feature, then defining the custom action one wants to add in. But...I only want my new menu item available for documents. One of my testers saw that the new menu item was on the folder drop down list also, and what do you know, test case failed!

So...I could either add code that points out to the dear user that one ought not use this with folders, or see if there was a way to hide the new menu item from folders - that is, the new menu item appears only for documents.

RegistrationType and RegistrationID to the rescue. These items are part of the custom action XML defined by the Feature.XML. Here's what I've been able to determine. RegistrationType allows for "ContentType" and "FileType" values, as well as List and ProgID.

Specifying "ContentType" is what I'm after. This will allow me to associate the new action with a specific content type. The RegistrationID element is used to specify the ID of the content type. To get this ID, open your document library settings, in the ContentType section click on the content type of interest, then grab the hex string in the URL after the "ctype=" parameter. Paste this value in to the RegistrationID value.

Alternatively, if I only want this feature to appear for ".xls" files, then I'd use the FileType RegistationType, and the value "xls" for the registationID. Repeat the CustomAction block for other file types.

The completed Feature.XML looks like:

Feature.xml:
<?xml version="1.0" encoding="utf-8" ?>
<Feature Id="1a8e5fae-577f-4cbd-addb-a31d875300a6"
Title="Copy Document"
Description="My custom document copy feature"
Version="1.0.0.0"
Scope="Web"
xmlns="http://schemas.microsoft.com/sharepoint/">
<ElementManifests>
<ElementManifest Location="CopyDocument.xml" />
</ElementManifests>
</Feature>


CopyDocument.xml:
<?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<!-- Per Item Dropdown (ECB)-->
<CustomAction
Id="Custom.PromoteDocument"
RegistrationType="ContentType"
RegistrationId="ctype=0x01010038C4691B76BEB34CB53E65CADDF82AD3"
Location="EditControlBlock"
Rights="EditListItems"
Title="Promote Document">
<UrlAction Url="~site/_layouts/MyCustomCopyDocument.aspx?List={ListId}&ID={ItemId}"/>
</CustomAction>
</Elements>

Note also the use of {ListId} and {ItemID} - I use this with my code behind file to get the SPList and SPListItem from the content SPWeb. With these I can then get to the attachment object of the SPListItem, so I can copy that document around.

4 comments:

Isha said...

Thank you! The bit about the RegistrationID and content types is JUST what i needed!

Anonymous said...

Hi Steve.
Nice Article indeed. I too was looking for the same solution where the folders are not supposed to display the menu item. But had one problem doing so. Whatever values I specify in the "RegistrationID", nothing would work except for "101" being the DL template ID. In this case the folders would also be showing the menu item.

In the Contents type section of library settings, I get "Documents" which gives me the ctype id. I tried doing as you've done but without success. Can you please help me in this matter.

Thanks in advance,
Vijay

Unknown said...

Great Post Steve,

I'm trying to add a feature "Add User" that will go directly to the add user page (_layouts/aclinv.aspx). it requires two parameters.

1. obj = {listId}
2. DOCUMENT&List = ?

Where is the DOCUMENT&List value?

don't ask me why I need this feature, we are implementing here SharePoint for the first time and the upper management doesn't like the way the "Edit Permissions" works in SharePoint.

they would rather have a drop down that will be populated from the active directory and give permissions like that.

I know there might be many complications with that approach, I would appreciate if i can get your input.

Thank You
MP

Anonymous said...

Great Post. Is there any way to isolate the new feature to a specific custom list rather than a content type?

please email me at
sales(at)cyberpine(dot)com

Thank you for any info.