Can a Single Custom Action Work Across All List Types?
February 21, 2010 2 Comments
A good friend of mine, Mark Rackley, posed a question to me yesterday…
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)
Lets build out our folder structure, and add in our feature.xml file, as well as our element manifest
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…
Ok, that went well. Now, let’s deploy the solution…
I’ll create a Custom List, Document Library, Announcements List, and a Task List.
And, then activate the feature…
And now, let’s go check the EditControlBlock of our lists…
Checking Tasks… nope.
How about our Custom list…. nope. Not looking good at this point…
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…
There it is! Let’s try our Document Library…
There as well! And our Tasks List? Bingo!
And also our Announcements List
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.
Dude, what a post, I am sure this will help out, especially when one needs a sanity check!
Phenomenal! This is such a valuable post.