1. Write a feature receiver and deploy it to a farm:
Open visual studio and create a blank class project.
Add a reference to SharePoint.dll (it will be on your SharePoint server \program files\common files\Microsoft shared\web server extensions\12\isapi\) I would suggest copying the dll's from there into one central location if you are not developing on a SharePoint server.
Open the class file and add the reference:
using Microsoft.SharePoint;
Now we are going to implement the feature receiver interface in our class:
public class SetupLookFeel : Microsoft.SharePoint.SPFeatureReceiver
{
public override void FeatureInstalled(SPFeatureReceiverProperties properties)
{
}
public override void FeatureUninstalling(SPFeatureReceiverProperties properties)
{
}
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
//Get the current SPWeb object to make changes to the web properties
SPWeb currentWeb = properties.Feature.Parent as SPWeb;
//Set the masterpage to our masterpages
currentWeb.MasterUrl = "_catalogs/masterpage/SystemMaster.master";
currentWeb.CustomMasterUrl = "_catalogs/masterpage/SiteMaster.master";
//Other options can be set here as well, i.e.
//
//currentWeb.ApplyTheme("ThemeName");
//currentWeb.CustomizeCss("cssFileName");
//Update the web with our changes
currentWeb.Update();
}
public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
{
//Get the current SPWeb object to make changes to the web properties
SPWeb currentWeb = properties.Feature.Parent as SPWeb;
//Set the masterpage back to the default OOB masterpage
currentWeb.MasterUrl = "_catalogs/masterpage/default.master";
currentWeb.CustomMasterUrl = "_catalogs/masterpage/default.master";
//Just make sure to undo other options that were set here as well, i.e.
//
//currentWeb.ApplyTheme("Default");
//currentWeb.RevertCss("");
//Update the web with our restored defaults.
currentWeb.Update();
}
}
Now that we have the code, compile it to make sure that things are in working order.
We must sign the project so that it may be placed in the GAC.
Go to the properties of the project, and select Signing. Click on the checkbox to sign the assembly, select <New> from the dropdown. Now give it a name (temp), uncheck the password box and click Ok. Back on the properties window, click save, and close the properties window.
Next we create a manifest file, and add some entries into it. (If you are lost here, go to my other blog post about deploying features.)
<Solution SolutionId="{NEW GUID HERE}" xmlns=http://schemas.microsoft.com/sharepoint/>
<Assemblies>
<Assembly DeploymentTarget="GlobalAssemblyCache" Location="LookFeelFeatureReceiver.dll">
</Assembly>
</Assemblies>
</Solution>
Finally, we need to add a cab file to hold the DLL and manifest.xml files so that we can deploy these to SharePoint.
(Also see the other blog post on this part if you are lost)
After a clean build, rename the cab to a wsp file, and copy to a SharePoint server.
Finally we are going to need to run some STSADM commands.
Stsadm.exe –o addsolution –filename LookFeelFeatureReceiver.wsp
Stsadm.exe –o deploysolution –name LookFeelFeatureReceiver.wsp –immediate –allowGacDeployment
The -allowGacDeployment is important here.
Well now that was not too difficult! We have a feature reciever on the farm (SharePoint will pass this DLL out to all front end servers and place this file in the GAC.) And now we can move on to creating a feature with a masterpage, cssFile, etc.
-Dan