Blog Home  Home Feed your aggregator (RSS 2.0)  
.Net Jonesie - VSeWSS: Feature Staples
A simple programmers blog
 
# Monday, March 31, 2008

Thanks to Chris Johnson I now know how to create a feature staple with VSeWSS.

If you don't know what a staple is then Chris has a good description on his blog.  You should read this first for more background but my simple explanation of a feature staple follows.

Feature staples are a way of attaching customisations to existing features and hence site definitions.  This is acheived by creating a feature that associates itself with another feature.  You can also add Feature Receiver code (which is like an event handler for feature activation) that lets you do all sorts of goodness that you can't do with CAML.

Feature stapling is the reccommened way of customising SharePoint.  Site definitions may appear to be a good way to go, but dont.  Andrew Connell explains why.

To create a staple you actually need to create two features:  the feature that you want activated and a feature to do the stapling. 

Update:  I just found a much better description of the process here.

VSeWSS 1.1 does not yet support feature stapling via an item template, but you can still do this via a neat trick that the VSeWSS team provided.  Here's the steps.

  1. Create an Empty VSeWSS project:


  2. Add a module for the feature you want stapled.  This this case I just used the default module that copies sample.txt.
  3. Switch to WSP View and refresh.
  4. Open the module feature.xml and change the scope to Site.
  5. Open the Module.xml for the new module and change the Url to "MyModule" and add RootWebOnly="FALSE":


  6. Deploy the solution and make sure that you get sample.txt in a new folder MyModule.
  7. Now for the stapler.  In the solution explorer, create a new folder called Stapler.  Add a new XML filed to this called element.xml.  This will contain the feature associations:

    This element.xml contains 3 associations for the new Module.  The Id GUID is from Module1.  Get this value from the WSP View of Module1 feature.xml.  The TemplateName is found in 12\TEMPLATE\1033\XML\WEBTEMP.XML - STS is the name of the templte and #0, #1, #2 is the configuration.  So, this staple associates Module1 with Blank Site, Team Site and Document Workspace.

    Make sure the element Id is a new unique GUID.  WSP uses this.

    Note: there are issues with the blank site.  I can't find the reference to the explaination of this.. will update when I do.
  8. Switch to WSP View and refresh.  You should see a new Feature appear for the staple called Untitiled1.  Rename the folders to the name of your stapler thus:


    You should also change the Title in the feature.xml.
  9. Edit the feature.xml for the Stapler and set the Scope to Farm:  
     
  10. Deploy and pray.
  11. Test & checking.  The stapler feature will be deployed to the farm.  Check the Farm Features to make sure it's there. VSeWSS will also deploy the module to the default site so you need to create a new site to test that the staple works. 
  12. Create a new Team site.  Use SharePoint designer to see if the MyModule folder is created.
  13. Now that you have the stapler working you can create a feature receiver to perform any code based actions.  I haven't done this part yet.  I'll post again when I do.

Normally you will use this method to deploy a master page, aspx page, css etc.  If this is the case then you probably don't need to copy these files to every sub-site, just to the root site.  Set RootWebOnly to TRUE if you want.  Remember that if Module1 is copying files to a library then you need Type=GhostableInLibrary for each file that is copied.

 

Monday, March 31, 2008 8:31:43 AM (New Zealand Standard Time, UTC+12:00)  #    Comments [0]   Sharepoint  | 
Comments are closed.
Copyright © 2012 Peter G Jones. All rights reserved.
DasBlog 'Portal' theme by Johnny Hughes.
Pick a theme: