<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:series="http://unfoldingneurons.com/"
	>

<channel>
	<title>SharePoint Magazine &#187; Paul Liebrand</title>
	<atom:link href="http://sharepointmagazine.net/author/liebrand/feed" rel="self" type="application/rss+xml" />
	<link>http://sharepointmagazine.net</link>
	<description>SharePoint Magazine is an online Magazine dedicated to the world of SharePoint</description>
	<lastBuildDate>Mon, 05 Jul 2010 09:14:11 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Introduction to SharePoint Feature Stapling &#8211; Part 2</title>
		<link>http://sharepointmagazine.net/technical/development/introduction-to-sharepoint-feature-stapling-part-2</link>
		<comments>http://sharepointmagazine.net/technical/development/introduction-to-sharepoint-feature-stapling-part-2#comments</comments>
		<pubDate>Wed, 05 Nov 2008 08:34:53 +0000</pubDate>
		<dc:creator>Paul Liebrand</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Technical]]></category>
		<category><![CDATA[event]]></category>
		<category><![CDATA[FeatureActivated]]></category>
		<category><![CDATA[features]]></category>
		<category><![CDATA[ListTemplates]]></category>
		<category><![CDATA[reciever]]></category>
		<category><![CDATA[sharepoint]]></category>
		<category><![CDATA[SPWeb]]></category>
		<category><![CDATA[stapling]]></category>

		<guid isPermaLink="false">http://sharepointmagazine.net/?p=1242</guid>
		<description><![CDATA[Welcome to part 2 of my Introduction to SharePoint Feature Stapling. In this small post, I’ll be providing some insight into the feature stapling lifecycle and also providing some potential solutions to some of the downsides of the feature stapling process.]]></description>
			<content:encoded><![CDATA[<p>Welcome to part 2 of my Introduction to SharePoint Feature Stapling. In <a href="http://sharepointmagazine.net/technical/development/introduction-to-sharepoint-feature-stapling-part-1">part 1</a> I explained the process of creating a feature stapler and associating it with a site definition. In this small post, I’ll be providing some insight into the feature stapling lifecycle and also providing some potential solutions to some of the downsides of the feature stapling process.</p>
<p><strong>Feature Stapling Lifecycle</strong></p>
<p>The actual lifecycle of the feature stapling process is not documented actually documented anywhere. The following information has been solely gathered based on my testing and experimenting with the process.</p>
<p>If we step back and look at a site definition file we know that the GLOBAL#0 site template is applied to all site definitions. Many of the Microsoft provided site definitions enable functionality through the use of the feature system. If you open up the STS site definition ONET.XML file, you will see two sections near the bottom called <strong>SiteFeatures</strong> and <strong>WebFeatures</strong>:</p>
<p><img src="http://sharepointmagazine.net/wp-content/uploads/2008/09/stsonet.png" border="0" alt="STS ONET" width="556" height="189" /></p>
<p>You will notice that in many of the Windows SharePoint Services site definition files the <strong>ListTemplates</strong> section is not populated with anything; they use list definition features instead. As you can see, the <strong>Team Site</strong> site definition points to a feature called <strong>TeamCollab</strong>. This feature makes list definitions available to the web that is being created.</p>
<p>So what does this all mean when it comes to feature association? The important thing to remember here is that any feature receivers you develop and associate to a site definition will get executed <strong>before</strong> any of the lists on that site have been provisioned. However, anything provisioned via the Global Site Definition will be available to your feature receiver.</p>
<p>This is not a problem if you simply want to create new lists, libraries, etc. However, if you are attempting to manipulate any lists that are part of the site definition you are associating with you will find yourself looking at a <strong>System.ArgumentException</strong> stating “Value does not fall within the expected ranged.”</p>
<p>The following image shows what happens when I create a Team Site that has my custom feature receiver associated to it:</p>
<p><img src="http://sharepointmagazine.net/wp-content/uploads/2008/09/exceptionmessage.png" border="0" alt="ExceptionMessage" width="604" height="371" /></p>
<p><strong>Solution</strong></p>
<p>We have already determined that feature receivers make it extremely easy for a developer to extend and customize out of the box site definitions without touching the files. But we run into a road block when we attempt to customize the lists and libraries that are part of that site definition.</p>
<p>One way I have used to get around this is to simply delay the customizations until after the site has completely provisioned.</p>
<p>The following is an example using the ThreadPool.QueueUserWorkItem method:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #0600FF;">override</span> <span style="color: #0600FF;">void</span> FeatureActivated<span style="color: #000000;">&#40;</span>SPFeatureReceiverProperties properties<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">using</span> <span style="color: #000000;">&#40;</span>SPWeb web <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span>SPWeb<span style="color: #000000;">&#41;</span>properties.<span style="color: #0000FF;">Feature</span>.<span style="color: #0000FF;">Parent</span><span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        ThreadPool.<span style="color: #0000FF;">QueueUserWorkItem</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">new</span> WaitCallback<span style="color: #000000;">&#40;</span>RunProcess<span style="color: #000000;">&#41;</span>, web.<span style="color: #0000FF;">Url</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span> 
&nbsp;
<span style="color: #0600FF;">private</span> <span style="color: #0600FF;">void</span> RunProcess<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> state<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
    Thread.<span style="color: #0000FF;">Sleep</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">5000</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span> 
&nbsp;
    <span style="color: #FF0000;">string</span> url <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span><span style="color: #000000;">&#41;</span>state<span style="color: #008000;">;</span>
    <span style="color: #0600FF;">using</span> <span style="color: #000000;">&#40;</span>SPSite site <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> SPSite<span style="color: #000000;">&#40;</span>url<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">using</span> <span style="color: #000000;">&#40;</span>SPWeb web <span style="color: #008000;">=</span> site.<span style="color: #0000FF;">OpenWeb</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #008080; font-style: italic;">// at this point, the site should be provisioned</span>
            <span style="color: #008080; font-style: italic;">// and we will now have access to all lists on it</span>
            SPList list <span style="color: #008000;">=</span> web.<span style="color: #0000FF;">Lists</span><span style="color: #000000;">&#91;</span><span style="color: #666666;">&quot;Shared Documents&quot;</span><span style="color: #000000;">&#93;</span><span style="color: #008000;">;</span>
            list.<span style="color: #0000FF;">Description</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Updated from Feature Receiver&quot;</span><span style="color: #008000;">;</span>
            list.<span style="color: #0000FF;">Update</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span> 
&nbsp;
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Why are we running on a different thread? Well, this allows the site provisioning process to complete and then we come back in a few seconds later to customize it as needed. Of course, the sample above is not 100% perfect. What happens if it takes 10 seconds to provision a site – well the method above would fail out.</p>
<p>A more elegant way would probably be to check the SPWeb.Provisioned property which is <strong>False</strong> until after the provisioning process has completed; but you get the general idea.</p>
<p><strong>Summary</strong></p>
<p>Hopefully this two part series has given you the necessary information needed to get started using SharePoint Feature Stapling and what potential issues to watch out for. There is many resources out on the Internet that cover other aspects of Feature Stapling, but I’ll list a few here for your reference:</p>
<p><a href="http://msdn.microsoft.com/en-us/library/bb861862.aspx">MSDN: Feature Stapling</a></p>
<p><a href="http://msdn.microsoft.com/en-us/library/bb862634.aspx">MSDN: Feature Event Receiver</a></p>
<p><a href="http://blogs.msdn.com/cjohnson/archive/2006/11/01/feature-stapling-in-wss-v3.aspx">http://blogs.msdn.com/cjohnson/archive/2006/11/01/feature-stapling-in-wss-v3.aspx</a></p>
<p><a href="http://www.sharepointnutsandbolts.com/2007/05/feature-stapling.html">http://www.sharepointnutsandbolts.com/2007/05/feature-stapling.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://sharepointmagazine.net/technical/development/introduction-to-sharepoint-feature-stapling-part-2/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Introduction to SharePoint Feature Stapling &#8211; Part 1</title>
		<link>http://sharepointmagazine.net/technical/development/introduction-to-sharepoint-feature-stapling-part-1</link>
		<comments>http://sharepointmagazine.net/technical/development/introduction-to-sharepoint-feature-stapling-part-1#comments</comments>
		<pubDate>Mon, 18 Aug 2008 10:00:10 +0000</pubDate>
		<dc:creator>Paul Liebrand</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Technical]]></category>
		<category><![CDATA[features]]></category>
		<category><![CDATA[stapling]]></category>
		<category><![CDATA[wspbuilder]]></category>

		<guid isPermaLink="false">http://sharepointmagazine.net/?p=385</guid>
		<description><![CDATA[The focus of this article is going to be on a concept called Feature Stapling. Most, if not all, SharePoint developers know that Microsoft frowns on modifications to the “Microsoft” owned files that support SharePoint.]]></description>
			<content:encoded><![CDATA[<p><strong>Features</strong> allow you to add new functionality to SharePoint or make simple site customizations in an easy and consistent way. Features can be scoped to the Farm, Web Application, Site, and Web level depending on the purpose of the feature. The basis of a feature is implemented using a feature.xml file, but may also contain other supporting files. More information on Features can be found on the Microsoft MSDN site at <a href="http://msdn.microsoft.com/en-us/library/ms460318.aspx">http://msdn.microsoft.com/en-us/library/ms460318.aspx</a>.</p>
<p>The focus of this article is going to be on a concept called <strong>Feature Stapling</strong>. Most, if not all, SharePoint developers know that Microsoft frowns on modifications to the “Microsoft” owned files that support SharePoint. If you modify these files you run the risk of your changes being broken with the installation of a service pack or hot fix. Sometimes this was your only option when attempting to customize SharePoint back in the WSS 2.0 days. The following KB article that outlines the supported / unsupported scenarios when it comes to modifying the default site definition files (<a href="http://support.microsoft.com/kb/898631">http://support.microsoft.com/kb/898631</a>).</p>
<p>Feature Stapling allows you to create a feature and then associate it with any site definition without ever touching the site definition files themselves. Your feature will be executed when the site is being provisioned.</p>
<p>As you read this series of articles I hope to explain how Feature Stapling works through the creation of a working feature and feature stapling example. I will also touch on some important points and considerations you need to be aware of about when in the life cycle of a site being provisioned your feature will be executed.</p>
<h3>Feature Stapling</h3>
<p><strong>Feature Stapling</strong> is achieved through the creation of another feature that defines the association of your regular Feature and the site definition you want to “staple” it too. In other words, you need to create two Features to achieve a complete Feature Stapling implementation.</p>
<h3>Creating Feature</h3>
<p>There are many different recommendations on how to go about creating SharePoint Features within Visual Studio from the layout to the deployment. In this article, I am going to use the method that works best for me. I use Visual Studio 2008, a class library, and WSP Builder (<a href="http://www.codeplex.com/wspbuilder">http://www.codeplex.com/wspbuilder</a>). WSP Builder is what I ultimately use to generate my solution file; however, it does have some features such as <strong>Copy to 12 Hive</strong>, and <strong>Recycle Application Pools</strong> that I used while creating my Feature.</p>
<p>In this scenario, I want to capture the Title and URL of any site that was created using the Team Site template in a central location.</p>
<p><strong>Step 1:</strong> Create the 12 hive folder structure down to my actual Feature, created a strong named key, and added a reference to the Microsoft.SharePoint.dll assembly.</p>
<p>The following is a screen capture of my project in Visual Studio:</p>
<p><a href="http://sharepointmagazine.net/wp-content/uploads/2008/08/visualstudiosolutionview.png"><img src="http://sharepointmagazine.net/wp-content/uploads/2008/08/visualstudiosolutionview-thumb.png" border="0" alt="VisualStudioSolutionView" width="322" height="245" /></a><br />
<strong>Step 2:</strong> Add a new class file in the root of the project folder called <strong>SampleFeatureReceiver.cs</strong> and use the following code:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">Microsoft.SharePoint</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF;">namespace</span> Liebrand.<span style="color: #0000FF;">Sample</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> SampleFeatureReceiver <span style="color: #008000;">:</span> SPFeatureReceiver
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">override</span> <span style="color: #0600FF;">void</span> FeatureActivated<span style="color: #000000;">&#40;</span>SPFeatureReceiverProperties properties<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">using</span> <span style="color: #000000;">&#40;</span>SPWeb web <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span>SPWeb<span style="color: #000000;">&#41;</span>properties.<span style="color: #0000FF;">Feature</span>.<span style="color: #0000FF;">Parent</span><span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>web.<span style="color: #0000FF;">IsRootWeb</span><span style="color: #000000;">&#41;</span>
                    return<span style="color: #008000;">;</span>
&nbsp;
                <span style="color: #0600FF;">using</span> <span style="color: #000000;">&#40;</span>SPSite site <span style="color: #008000;">=</span> web.<span style="color: #0000FF;">Site</span><span style="color: #000000;">&#41;</span>
                <span style="color: #000000;">&#123;</span>
                    <span style="color: #0600FF;">using</span> <span style="color: #000000;">&#40;</span>SPWeb rootWeb <span style="color: #008000;">=</span> site.<span style="color: #0000FF;">RootWeb</span><span style="color: #000000;">&#41;</span>
                    <span style="color: #000000;">&#123;</span>
                        SPList createdSites <span style="color: #008000;">=</span> GetProvisionedSitesListId<span style="color: #000000;">&#40;</span>rootWeb<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                        SPListItem newItem <span style="color: #008000;">=</span> createdSites.<span style="color: #0000FF;">Items</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
                        newItem<span style="color: #000000;">&#91;</span><span style="color: #666666;">&quot;Title&quot;</span><span style="color: #000000;">&#93;</span> <span style="color: #008000;">=</span> web.<span style="color: #0000FF;">Title</span><span style="color: #008000;">;</span>
                        newItem<span style="color: #000000;">&#91;</span><span style="color: #666666;">&quot;Url&quot;</span><span style="color: #000000;">&#93;</span> <span style="color: #008000;">=</span> web.<span style="color: #0000FF;">Url</span><span style="color: #008000;">;</span>
                        newItem.<span style="color: #0000FF;">Update</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                    <span style="color: #000000;">&#125;</span>
                <span style="color: #000000;">&#125;</span>
             <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">private</span> SPList GetProvisionedSitesListId<span style="color: #000000;">&#40;</span>SPWeb rootWeb<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">try</span>
            <span style="color: #000000;">&#123;</span>
                SPList list <span style="color: #008000;">=</span> rootWeb.<span style="color: #0000FF;">Lists</span><span style="color: #000000;">&#91;</span><span style="color: #666666;">&quot;Provisioned Sites&quot;</span><span style="color: #000000;">&#93;</span><span style="color: #008000;">;</span>
                <span style="color: #0600FF;">return</span> list<span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
            <span style="color: #0600FF;">catch</span> <span style="color: #000000;">&#40;</span>ArgumentException<span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                Guid listId <span style="color: #008000;">=</span> rootWeb.<span style="color: #0000FF;">Lists</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Provisioned Sites&quot;</span>,
                    <span style="color: #666666;">&quot;This list contains all the sites that have been provisioned.&quot;</span>,
                    SPListTemplateType.<span style="color: #0000FF;">GenericList</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
                SPList list <span style="color: #008000;">=</span> rootWeb.<span style="color: #0000FF;">Lists</span><span style="color: #000000;">&#91;</span>listId<span style="color: #000000;">&#93;</span><span style="color: #008000;">;</span>
&nbsp;
                list.<span style="color: #0000FF;">Fields</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Url&quot;</span>, SPFieldType.<span style="color: #0000FF;">URL</span>, <span style="color: #0600FF;">false</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                SPField field <span style="color: #008000;">=</span> list.<span style="color: #0000FF;">Fields</span><span style="color: #000000;">&#91;</span><span style="color: #666666;">&quot;Url&quot;</span><span style="color: #000000;">&#93;</span><span style="color: #008000;">;</span>
&nbsp;
                SPView view <span style="color: #008000;">=</span> list.<span style="color: #0000FF;">DefaultView</span><span style="color: #008000;">;</span>
                view.<span style="color: #0000FF;">ViewFields</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>field<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                view.<span style="color: #0000FF;">Update</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
                list.<span style="color: #0000FF;">Update</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
                <span style="color: #0600FF;">return</span> list<span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">override</span> <span style="color: #0600FF;">void</span> FeatureDeactivating<span style="color: #000000;">&#40;</span>SPFeatureReceiverProperties properties<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">override</span> <span style="color: #0600FF;">void</span> FeatureInstalled<span style="color: #000000;">&#40;</span>SPFeatureReceiverProperties properties<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">override</span> <span style="color: #0600FF;">void</span> FeatureUninstalling<span style="color: #000000;">&#40;</span>SPFeatureReceiverProperties properties<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>This code basically adds the URL of the site being provision to a listed called <strong>Provisioned Sites</strong> that is located in the root site. If the list is not found, the list is created.</p>
<p><strong>Step 3: </strong>Add a new XML file called <strong>feature.xml</strong> to the feature folder and paste the following contents:</p>
<pre>&lt;?xml version=<span class="str">"1.0"</span> encoding=<span class="str">"utf-8"</span> ?&gt;
&lt;Feature xmlns=<span class="str">"http://schemas.microsoft.com/sharepoint/"</span>
         Id=<span class="str">"2B3451F0-BC93-41A4-9FAD-3A81861D651A"</span>
         Title=<span class="str">"Liebrand Feature Sample"</span>
         Description=<span class="str">"This is a feature that will be used to demonstrate feature stapling."</span>
         Scope=<span class="str">"Web"</span>
         Hidden=<span class="str">"False"</span>
         Version=<span class="str">"1.0.0.0"</span>
         ReceiverAssembly=<span class="str">"Liebrand.Sample, Version=1.0.0.0, Culture=neutral, PublicKeyToken=057a20dd10f3b267"</span>
         ReceiverClass=<span class="str">"Liebrand.Sample.SampleFeatureReceiver"</span>&gt;
&lt;/Feature&gt;</pre>
<div><strong>Note:</strong> The Id attribute value was generated using the <strong>Create GUID</strong> menu item from the Tools menu in Visual Studio.</div>
<h3>Creating the Stapling Feature feature</h3>
<p>At this point, our primary Feature is ready to go. The last step is to simply create another Feature that will associate my LiebrandSample Feature with the <strong>Team Site</strong> site definition.</p>
<p><strong>Step 1:</strong> Add another folder under the <strong>FEATURES</strong> folder called <strong>LiebrandSampleStapler</strong> and add a file called <strong>feature.xml</strong> then paste the following contents into it:</p>
<div>
<pre>&lt;?xml version=<span class="str">"1.0"</span> encoding=<span class="str">"utf-8"</span> ?&gt;
&lt;Feature xmlns=<span class="str">"http://schemas.microsoft.com/sharepoint/"</span>
         Id=<span class="str">"C384D136-79A8-48BD-AF73-C630547F4D8E"</span>
         Title=<span class="str">"Liebrand Sample Stapler"</span>
         Description=<span class="str">"This feature staples the LiebrandSample feature to the Team Site site definition."</span>
         Scope=<span class="str">"Farm"</span>
         Hidden=<span class="str">"False"</span>
         Version=<span class="str">"1.0.0.0"</span>&gt;

  &lt;ElementManifests&gt;
    &lt;ElementManifest Location=<span class="str">"elements.xml"</span> /&gt;
  &lt;/ElementManifests&gt;

&lt;/Feature&gt;</pre>
</div>
<p><strong>Step 2:</strong> Add a XML file called <strong>elements.xml</strong> to the <strong>LiebrandSampleStapler</strong> folder and paste the following:</p>
<pre>&lt;?xml version=<span class="str">"1.0"</span> encoding=<span class="str">"utf-8"</span> ?&gt;
&lt;Elements xmlns=<span class="str">"http://schemas.microsoft.com/sharepoint/"</span>&gt;
  &lt;FeatureSiteTemplateAssociation Id=<span class="str">"2B3451F0-BC93-41A4-9FAD-3A81861D651A"</span>
                                  TemplateName=<span class="str">"STS#0"</span>/&gt;
&lt;/Elements&gt;</pre>
<p>The ID attribute in the <strong>FeatureSiteTemplateAssociation</strong> element should match the ID of the Feature we created at the beginning of this article. The TemplateName attribute should match the site definition name and configuration ID found in the webtemp.xml file located in C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\1033\XML. Since we want to associate our new Feature to all Team Site sites we specify <strong>STS#0</strong>. STS is the name of the Template and 0 is the configuration ID for the Team Site.</p>
<p>At this point we are ready to deploy our new features and test it out.</p>
<h3>Deployment</h3>
<p>First build your project to insure you have no build errors and to generate the assembly Liebrand.Sample.dll.</p>
<p>To deploy these new Features using WSP Builder simply,</p>
<ul>
<li>Right-click on the project name and select <strong>WSPBuilder</strong>, then click <strong>Copy to GAC</strong>. This will copy the assembly into the Global Assembly Cache.</li>
<li>Right-click on the project name and select <strong>WSPBuilder</strong>, then click <strong>Copy to 12 hive</strong>. This will copy the 12 hive folder structure in your project to the SharePoint 12 hive folder</li>
</ul>
<p><a href="http://sharepointmagazine.net/wp-content/uploads/2008/08/wspbuildermenu.png"><img src="http://sharepointmagazine.net/wp-content/uploads/2008/08/wspbuildermenu-thumb.png" border="0" alt="WSPBuilderMenu" width="466" height="264" /></a></p>
<ul>
<li>Install and activate the Features by running the following commands:</li>
</ul>
<p>stsadm -o installfeature -name LiebrandSample</p>
<p>stsadm -o installfeature -name LiebrandSampleStapler</p>
<h3>Test</h3>
<p>At this point you can create a new sub-site using the <strong>Team Site</strong> template and you should see a new list called <strong>Provisioned Sites</strong> get created at the root site with a new entry added that will point back to the site you created.</p>
<p>After creating 3 team sites, this is what the <strong>Provisioned Sites</strong> list looked like:</p>
<p><a href="http://sharepointmagazine.net/wp-content/uploads/2008/08/provisionsiteslisting.png"><img src="http://sharepointmagazine.net/wp-content/uploads/2008/08/provisionsiteslisting-thumb.png" border="0" alt="ProvisionSitesListing" width="545" height="226" /></a></p>
<h3>Summary</h3>
<p>Features Stapling offers a great way for developers to extend, change, or customize the out-of-the-box site definitions without ever touching them. Hopefully this article gives you an idea of where you can utilize Feature Stapling. In the next article of this series, I am going to cover when Feature Stapling occurs in the creation of a site and some key points you need to be aware of when it comes to what elements are available to you when your feature is executed.</p>
]]></content:encoded>
			<wfw:commentRss>http://sharepointmagazine.net/technical/development/introduction-to-sharepoint-feature-stapling-part-1/feed</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
	</channel>
</rss>
