ONET.XML
Part 4 is the real difference in the site definition we are creating and those offered in many books and blogs. Except for the methodology I am presenting, I haven’t really offered anything new! Today we will start to deviate. The ONET.xml file is fairly simple when you get to using it a few times! The ONET.XML file I am proposing is very simple and not much in it except for some OOTB xml and the only thing that will change in this instance is adding all the features we have created and two more new features! Feature receiver for code and a feature stapler to add the code to the site definition. But first let’s complete the ONET.XML file:
1. NavBars Element: We will keep the default quick launch so we will leave it alone!

2. List Templates Element is empty we’ll leave the same
3. Document Templates we will leave as is
4. Configurations elements: We’ll only have one so we will delete all but the default configuration.
a. We’ll keep <Configuration ID="0" Name="Default">
b. We’ll delete all the List Elements
i. We are using features to provision the lists
ii. The only configuration elements that are not empty is: Site Features and Web features
iii. WOW! This is in concert with the whole idea around the feature solution framework!
5. Modules elements: We will delete all the modules.

6. We will now add the features we have created to this point in the WSPBuilder project

7. We are done with ONET.XML (Easy Huh!)
a. But wait we haven’t provisioned default.aspx
i. It is normally provisioned via a module in ONET.XML
ii. We will provision it in a new feature!
1. So we can add a feature receiver
2. Add a new feature folder ABCTeamSiteRec
a. Build the site Definition as we need the strong name
b. Use Red Gate’s reflector to get the needed information
c. Drop the DLL into Red Gate and get the needed information

8. Add the following in the feature XML file:
<?xml version="1.0" encoding="utf-8"?>
<Feature
Id="{9F2EA305-7F72-40fd-A0E8-5353A5CBB251}"
Title="A Company feature: SiteDefinition Activation"
Description="SiteDefinition Activation"
Version="1.0.0.0"
Scope="Web"
Hidden="TRUE"
ImageUrl="ABCteamSite/company10.jpg"
ReceiverAssembly="ABCSiteDef, Version=1.0.0.0, Culture=neutral, PublicKeyToken=e540898f86a0353c"
ReceiverClass="ABCSiteDef.FeatureReceiver" xmlns="http://schemas.microsoft.com/sharepoint/">
<ElementManifests>
<ElementManifest Location="elements.xml"/>
</ElementManifests>
</Feature>
9. Copy the default.aspx page to this feature folder and then add the following into the elements. Xml file:
<?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Module Name="HomePage" Path="" Url="">
<File
Url="default.aspx"
Type="Ghostable"
IgnoreIfAlreadyExists="False"/>
</Module>
</Elements>
10. Next we need to add the feature receiver add the following into a class at the root of the site not in the 12 hive
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;
using Microsoft.SharePoint.Navigation;
using Microsoft.SharePoint.Administration;
namespace ABCSiteDef
{
public class FeatureReceiver : SPFeatureReceiver
{
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
SPWeb currentWeb = null;
SPSite currentSite = null;
object oParent = properties.Feature.Parent;
if (properties.Feature.Parent is SPWeb)
{
currentWeb = (SPWeb)oParent;
currentSite = currentWeb.Site;
}
else
{
currentSite = (SPSite)oParent;
currentWeb = currentSite.RootWeb;
}
// Get the web part manager
SPLimitedWebPartManager mgr = currentWeb.GetLimitedWebPartManager("default.aspx", System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared);
// Tasks List
SPList list = currentWeb.Lists["Tasks"];
// Instantiate the web part
ListViewWebPart wp = new ListViewWebPart();
wp.ZoneID = "Left";
wp.ListName = list.ID.ToString("B").ToUpper();
wp.ViewGuid = list.DefaultView.ID.ToString("B").ToUpper();
mgr.AddWebPart(wp, "left", 1);
mgr.AddWebPart(wp, "left", 1);
// Calender List
SPList list7 = currentWeb.Lists["Calendar"];
// Instantiate the web part
ListViewWebPart wp7 = new ListViewWebPart();
wp7.ZoneID = "Left";
wp7.ListName = list7.ID.ToString("B").ToUpper();
wp7.ViewGuid = list7.DefaultView.ID.ToString("B").ToUpper();
mgr.AddWebPart(wp7, "left", 3);
mgr.AddWebPart(wp7, "left", 3);
// Internal Contacts List
SPList list2 = currentWeb.Lists["Internal Contacts"];
// Instantiate the web part
ListViewWebPart wp2 = new ListViewWebPart();
wp2.ZoneID = "Right";
wp2.ListName = list2.ID.ToString("B").ToUpper();
wp2.ViewGuid = list2.DefaultView.ID.ToString("B").ToUpper();
mgr.AddWebPart(wp2, "Right", 3);
// Announcements List
SPList list3 = currentWeb.Lists["Announcements"];
// Instantiate the web part
ListViewWebPart wp3 = new ListViewWebPart();
wp3.ZoneID = "Right";
wp3.ListName = list3.ID.ToString("B").ToUpper();
wp3.ViewGuid = list3.DefaultView.ID.ToString("B").ToUpper();
mgr.AddWebPart(wp3, "Right", 4);
// Links List
SPList list4 = currentWeb.Lists["Links"];
// Instantiate the web part
ListViewWebPart wp4 = new ListViewWebPart();
wp4.ZoneID = "Right";
wp4.ListName = list4.ID.ToString("B").ToUpper();
wp4.ViewGuid = list4.DefaultView.ID.ToString("B").ToUpper();
mgr.AddWebPart(wp4, "Right", 5);
currentWeb.Update();
}
public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
{
/* no op */
}
public override void FeatureInstalled(SPFeatureReceiverProperties properties)
{
/* no op */
}
public override void FeatureUninstalling(SPFeatureReceiverProperties properties)
{
/* no op */
}
}
}

11. Next we need to add a feature stapler so the code and thus the web parts will be added to default.aspx when the site is provisioned!
12. Add A new feature folder to the WSPBuilder solution
a. Name it ABCTeamSiteRecStapler
i. Add the following feature code:
<?xml version="1.0" encoding="utf-8" ?>
<Feature Id="{5FAFFFF9-50BF-4fea-BC70-7AF3266AFC4E}" note: make sure the guid points to the feature receiver
Title="$Resources:MultiLangStaplingFeatureName"
Description="$Resources:MultiLangstaplingFeatureDescription"
Version="12.0.0.0"
Scope="Site"
xmlns="http://schemas.microsoft.com/sharepoint/"
DefaultResourceFile="_Res">
<ElementManifests>
<ElementManifest Location="elements.xml"/>
</ElementManifests>
</Feature>
13. Add the following elements.xml file
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<FeatureSiteTemplateAssociation
Id="{3D6DC874-154C-4e3d-AE0E-9A3F21D69136}"
TemplateName="ABCTeamSite#0" />
</Elements>
