Advertisements

Can a Single Custom Action Work Across All List Types?


A good friend of mine, Mark Rackley, posed a question to me yesterday…

Can I create one Custom Action that will work on all list types or do I have to create a separate custom action for each list type?

Which was a great question, and one that throughout all of the times I have spoken at various events and user groups on Custom Actions, I had never heard asked. So, I thought I would post a blog on this, and answer the question for others as well. Thanks for the ? (“question, Mark”)

Well, why don’t we see what we can do – I’ll take you through the trial and error process, to see if we can make this work.

So, let’s fire up Visual Studio, and get started, and let’s create a new blank WSP Builder Project (as I know Mark is a big fan of STSDEV)

image

Lets build out our folder structure, and add in our feature.xml file, as well as our element manifest

image

In our Feature file, let’s scope this out to the Site Collection, and fill in some of the other details…

   1: <?xml version="1.0" encoding="utf-8" ?>
   2: <Feature xmlns="http://schemas.microsoft.com/sharepoint/" 
   3:          Id="{842E1000-139E-4e3e-A747-F6E01B2A5AAE}" 
   4:          Title="MarksCustomAction" 
   5:          Description="Mark's Custom Action" 
   6:          Scope="Site" 
   7:          Version="1.0.0.0" 
   8:          Hidden="false" 
   9:          ImageUrl="GraceHunt\Grace-Hunt.gif">
  10:  <ElementManifests>
  11:    <ElementManifest Location="manifest.xml" />
  12:  </ElementManifests>
  13: </Feature>
  14:  

Now, to populate our ElementManifest, which will contain our CustomAction Element, let’s refer to the CustomAction Element section of the Windows SharePoint Services 3.0 SDK.

   1: <?xml version="1.0" encoding="utf-8" ?>
   2: <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
   3:   <CustomAction
   4:       Id="MarksCustomAction"
   5:       Location="EditControlBlock"
   6:       Title="Grace-Hunt Website"
   7:       RegistrationType="List"
   8:       Sequence="12345">
   9:     <UrlAction Url="http://www.grace-hunt.com" />
  10:   </CustomAction>
  11: </Elements>
  12:  

Now, we know, especially if you’ve been to any of my sessions on Custom Actions, that the only thing you REALLY need in here is the Title attribute, but, we’ll add an Id, Location  – the Edit Control Block, a Title, set the RegistrationType to List, and, let’s give it a sequence number of 12345, and set the UrlAction to be http://www.grace-hunt.com.

Now, let’s deploy, and see what happens…

Using STSADM, let’s add the solution to our Farm. This will also give us a sanity check, to make sure that we have no errors in our feature. Otherwise, it would kinda yell at us…

image

Ok, that went well. Now, let’s deploy the solution…

image 

I’ll create a Custom List, Document Library, Announcements List, and a Task List.

image

And, then activate the feature…

image 

And now, let’s go check the EditControlBlock of our lists…

Checking Tasks… nope.

image

How about our Custom list…. nope. Not looking good at this point…

 image

And also checking the others…nothing. Well, this didn’t pan out too well. Let’s try something different. Since all content types inherit from the System content type, whose ID is 0x, let’s see if we map to that content type, if we have some success… so, let’s update our ElementManifest to the following…

   1: <?xml version="1.0" encoding="utf-8" ?>
   2: <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
   3:   <CustomAction
   4:       Id="MarksCustomAction"
   5:       Location="EditControlBlock"
   6:       Title="Grace-Hunt Website"
   7:       RegistrationType="ContentType"
   8:       RegistrationId="0x"
   9:       Sequence="12345">
  10:     <UrlAction Url="http://www.grace-hunt.com" />
  11:   </CustomAction>
  12: </Elements>
  13:  

and re-deploy, and see what happens. Let’s check our Custom List…

image

There it is! Let’s try our Document Library…

image

There as well! And our Tasks List? Bingo!

image

And also our Announcements List

image

So, as you can see, you can get a Custom Action to appear across all list types, by binding your Custom Action to the registration type of List, and  the base content type of 0x, and you can get a Custom Action to work across all list types, as all content types inherit from the System content type, 0x.

For more Custom Action resources, try this search against my blog.

 

Advertisements

About Geoff Varosky
Geoff Varosky is a Senior Architect for BlueMetal Architects, based out of Watertown, MA. He has been architecting and developing web based applications his entire career, and has been working with SharePoint for the past 13 years. Geoff is an active member of the SharePoint community, Co-Founder and Co-Organizer of the Boston Area SharePoint Users Group, co-founder for the Boston Office 365 Users Group, co-organizer for SharePoint Saturday Boston and speaks regularly at SharePoint events and user groups.

2 Responses to Can a Single Custom Action Work Across All List Types?

  1. fabian says:

    Dude, what a post, I am sure this will help out, especially when one needs a sanity check!

  2. mcccxhtml says:

    Phenomenal! This is such a valuable post.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: