Advertisements

Combining Multiple CustomAction Elements Together


I’ve been slowly, but surely, getting the questions asked during my SharePoint Saturday Boston presentation, so, here goes the next one.

Can you combine multiple custom actions within a feature?

YES! You sure can! In my 4th demonstration (Custom Action Groups), I showed this within my ElementManifest file (manifest.xml), where I defined a CustomActionGroup, as well as 4 additional CustomAction elements within a single manifest file. See code example below:

   1: <?xml version="1.0" encoding="utf-8" ?>
   2: <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
   3:   <CustomActionGroup Id="HelpResources"
   4:        Location="Microsoft.SharePoint.SiteSettings"
   5:        Title="CustomAction Resources on MSDN" />
   6:  
   7:   <CustomAction Id="CustomActionLocsAndIds" 
   8:                 Title="Custom Action Locations and Ids" 
   9:                 GroupId="HelpResources" 
  10:                 Location="Microsoft.SharePoint.SiteSettings" 
  11:                 Sequence="0">
  12:     <UrlAction Url="http://msdn.microsoft.com/en-us/library/bb802730.aspx"/>
  13:   </CustomAction>
  14:   
  15:   <CustomAction Id="CustomActionElement"
  16:                 Title="CustomAction Element"
  17:                 GroupId="HelpResources"
  18:                 Location="Microsoft.SharePoint.SiteSettings"
  19:                 Sequence="1">
  20:     <UrlAction Url="http://msdn.microsoft.com/en-us/library/ms460194.aspx"/>
  21:   </CustomAction>
  22:   
  23:   <CustomAction Id="CustomActionGroupElement"
  24:                 Title="CustomActionGroup Element"
  25:                 GroupId="HelpResources"
  26:                 Location="Microsoft.SharePoint.SiteSettings"
  27:                 Sequence="2">
  28:     <UrlAction Url="http://msdn.microsoft.com/en-us/library/ms438085.aspx"/>
  29:   </CustomAction>
  30:  
  31:   <CustomAction Id="HideCustomAction"
  32:                 Title="HideCustomAction Element"
  33:                 GroupId="HelpResources"
  34:                 Location="Microsoft.SharePoint.SiteSettings"
  35:                 Sequence="3">
  36:     <UrlAction Url="http://msdn.microsoft.com/en-us/library/ms414790.aspx"/>
  37:   </CustomAction>
  38: </Elements>

The person who asked this question had a business need to create a lot of custom actions, however, did not want to have a feature built for each one, even though features are handy ways of deploying functionality to SharePoint, if you have hundreds of features, that can become a management nightmare.

I also mentioned, that what you can do is separate these out into functional ElementManifest files – as you can have any number of them defined in your feature, and they do not all need to be named elements.xml, or manifest.xml. A good example of this can be seen in the 12 Hive FEATURES folder, looking at some of the built in CustomAction elements and CustomActionGroup elements.

For instance, if you wanted to break out your manifest definition files into one for each CustomActionGroup, you can do so easily, by specifying different files – code example below.

   1: <?xml version="1.0" encoding="utf-8" ?>
   2: <Feature xmlns="http://schemas.microsoft.com/sharepoint/"
   3:          Id="{FFC864FD-C78D-4fd0-8F18-963D1EA59E0C}"
   4:          Title="SPS.CustomActionGroup"
   5:          Description="Custom Action Grouping example"
   6:          Scope="Site"
   7:          Version="1.0.0.0"
   8:          Hidden="false"
   9:          >
  10:   <ElementManifests>
  11:     <ElementManifest Location="MSDNResources.xml"/>
  12:     <ElementManifest Location="BlogResources.xml"/>
  13:     <ElementManifest Location="TwitterResources.xml"/>
  14:   </ElementManifests>
  15: </Feature>

 

This will make not only the management of features easier within SharePoint as far as managing what gets activated, also the management of the solution as well, so you are not managing 400 CustomAction elements within a single file, you can break them out as needed.

And to answer the question before it gets asked in this entry’s comments – the CustomActionGroup does not need to be defined within the same file as its CustomAction elements. You could break it down into CustomActionGroups.xml and CustomActions.xml if you’d like to separate them out.

Again – the names of the ElementManifest XML definition files do not matter – as long as they are referenced within the feature.xml file (this filename MUST be feature.xml), then you are all set. They really do not even need to have an XML definition, as long as it is declared at the top of the XML file, they will be interpreted as XML files.

 

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.

One Response to Combining Multiple CustomAction Elements Together

  1. Pingback: Separate Tab in Ribbon with separate custom action button into that tab with multiple features » Rent in London

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: