This is a repost of an article that was lost due to a server crash.
One of the nicest things about Features in the new version of SharePoint is their ability to be added to a Site Definition by default. When you add a Feature to a Site Definition, that Feature is automatically available on a SharePoint site when you create a SharePoint site from the given Site Definition.
This functionality allows developers to build Features and plug them into any Site Definition they choose. In the last version of SharePoint, functionality that can now be delivered in the form of a Feature had to be registered and configured for each Site Definition that utilized the functionality. This is no longer the case because Features encapsulate of all the functionality they deliver.
Plug and play functionality
The relationship between Site Definitions and Features reminds me of the Plug and Play architecture Windows uses to add hardware to your computer.
Windows is a platform which requires a driver to recognize a particular piece of hardware. The driver is responsible for knowing everything about the hardware and it defines how Windows interacts and utilizes the hardware.
SharePoint and Site Definitions are like Windows in this analogy and Features are the hardware. The Feature.xml file acts like a driver that tells SharePoint and Site Definitions everything about the Feature and defines how SharePoint and the Site Definition interact with and utilize the Feature.
Adding Features to Site Definitions
In the Creating a Custom Document Library Feature in WSS V3 / MOSS 2007 article the SharePoint Feature architecture and the process to create a Feature is explained. Once you have created your own custom Feature you can easily add it to a custom Site Definition. This is perhaps the easiest thing I have found out how to do in the SharePoint V3 so far. Please see the Creating a custom Site Definition in WSS V3 / MOSS 2007 article to learn how to create a custom Site Definition.
This short list of tasks will show you how to add a Feature to a Site Definition.
Step 1: Edit the ONET.XML file for the Site Definition you wish to add the feature to.
Step 2: Reset IIS on the SharePoint server.
Step 3: Create a new SharePoint site based on the Site Definition you added the Feature to.
Short list, eh? See, I told you this was simple!
Step 1: Edit the ONET.XML file for the Site Definition you wish to add the feature to.
This example assumes you have created a custom Site Definition named SAMPLE. Please see the Creating a custom Site Definition in WSS V3 / MOSS 2007 article for instructions.
Open the ONET.XML file for the Site Definition you wish to edit.
The ONET.XML file can be found at the following location on the SharePoint server:
C:Program FilesCommon FilesMicrosoft Sharedweb server extensions12TEMPLATESiteTemplatesSAMPLEXMLONET.XML
Find the section in the ONET.XML file that corresponds to the configuration for the Sample Team Site. The XML Looks like this:
In the
The
Save the ONET.XML file.
Step 2: Reset IIS on the SharePoint server.
On the SharePoint server type iisreset on the command line and wait for IIS to reset.
Step 3: Create a new SharePoint site based on the Site Definition you added the Feature to.
Open Internet Explorer.
Browse to the http://SharePointServerName/SiteDirectory/ site.
Click Create Site
In the Title and URL Name textboxes enter CustomDocLibFeatureSite
In the Template Selection area of the web page click the Custom Site Definitions tab and select the Sample Site template.
Click the Create button.
When the newly created web site appears, click Site Actions and select Site Settings.
Under the Site Administration section, click the Site Features link.
You will see you Custom Document Library Feature in the list!
To activate the Feature, click on the Activate Button next to the Feature in the list.
To create your own Custom Document Library based on this Feature follow these steps:
Click Site Settings
Click Create
Click Custom Document Library
Fill in the required information and create the Custom Document Library.
If you created a custom Document Template in the Document Template dropdown select Custom Document Library for the template.
Click Create.
If you created a custom Document Template clicking the new button on the Custom Document Library toolbar will open the custom Document Template you created.
The beat goes on
Let’s take things one step further now. Instead of just adding the Custom Document Library Feature to the Site Definition and making it available, let’s create a Custom Document Library list from the Feature when the site is created. This way users will not have to create the Custom Document Library list themselves after the site is created.
The tasks to do this are just as simple as the tasks we just performed. Here is a list of the tasks necessary to make the Custom Document Library Feature list created by default when the site is created from our custom Site Definition.
Step 1: Edit the ONET.XML file for the Site Definition you wish to create the custom Document Library list on.
Step 2: Reset IIS on the SharePoint server.
Step 3: Create a new SharePoint site based on the Site Definition you added the Feature to.
Step 1: Edit the ONET.XML file for the Site Definition you wish to create the custom Document Library list on.
Make sure you are editing the same custom Site Definition that you added the Feature to. If you try to create a list for a Site Definition that does not implement the Feature the list relies upon, an error will occur during site creation indicating the Feature the list relies upon is not available.
This example assumes you have created a custom Site Definition named SAMPLE. Please see the Creating a custom Site Definition in WSS V3 / MOSS 2007 article for instructions.
Open the ONET.XML file for the Site Definition you wish to edit.
The ONET.XML file can be found at the following location on the SharePoint server:
C:Program FilesCommon FilesMicrosoft Sharedweb server extensions12TEMPLATESiteTemplatesSAMPLEXMLONET.XML
In the
Type="4000" Title="Custom Document Library" Url="Custom Document Library" QuickLaunchUrl="Custom Document Library/Forms/AllItems.aspx" /> *Note: You can use your own custom Resources file to provide the values for the Title, UTL, and QuickLaunchUrl attributes. Please see the Creating a Custom Document Library Feature in WSS V3 / MOSS 2007 article for further details. If you have already created a custom Resource file as described in the Creating a Custom Document Library Feature in WSS V3 / MOSS 2007 article your XML will look like this: Type="4000" Title="$Resources:customDocumentLibrary,customDocumentLibrary_Title;" Url="$Resources:customDocumentLibrary,customDocumentLibrary_Folder;" QuickLaunchUrl="$Resources:customDocumentLibrary,customDocumentLibrary_Folder;/Forms/AllItems.aspx" /> Save the ONET.XML file. Step 2: Reset IIS on the SharePoint server. On the SharePoint server type iisreset on the command line and wait for IIS to reset. Step 3: Create a new SharePoint site based on the Site Definition you added the Feature to. Open Internet Explorer. Browse to the http://SharePointServerName/SiteDirectory/ site. Click Create Site In the Title and URL Name textboxes enter CustomDocLibFeatureListCreatedSite In the Template Selection area of the web page click the Custom Site Definitions tab and select the Sample Site template. Click the Create button. When the newly create web site appears you will see the Custom Document Library list link on the QuickLaunch navigation menu. Click the Custom Document Library link to go to the Custom Document Library list. The Midas touch! Let’s put the finishing touches on our work now. In addition to creating the list by default, let’s place a view of the Custom Document Library list on the home page of our custom Site Definition when the site is created. Once again, this is a very simple task to perform. Here are the steps: Step 1: Edit the ONET.XML file for the Site Definition you wish to create a default view on the home page of the custom Document Library list on. Step 2: Reset IIS on the SharePoint server. Step 3: Create a new SharePoint site based on the Site Definition you added the Feature to. Step 1: Edit the ONET.XML file for the Site Definition you wish to create a default view on the home page of the custom Document Library list on. Make sure you are editing the same custom Site Definition that you added the Feature to and created the list on be default. If you try to create a list for a Site Definition that does not implement the Feature the list relies upon an error will occur during site creation indicating the Feature the list relies upon is not available. If you try to create a view of the list and that list has not been automatically created you will get an error during site creation that tells you the list does not exist. (Well, actually the error is ‘Cannot complete this action’) This example assumes you have created a custom Site Definition named SAMPLE. Please see the Creating a custom Site Definition in WSS V3 / MOSS 2007 article for instructions. Open the ONET.XML file for the Site Definition you wish to edit. The ONET.XML file can be found at the following location on the SharePoint server: C:Program FilesCommon FilesMicrosoft Sharedweb server extensions12TEMPLATESiteTemplatesSAMPLEXMLONET.XML Find the ]]> The *Note: You can use your own custom Resources file to provide the value for the List attribute. Please see the Creating a Custom Document Library Feature in WSS V3 / MOSS 2007 article for further details. If you have already created a custom Resource file as described in the Creating a Custom Document Library Feature in WSS V3 / MOSS 2007 article your XML will look like this: Save the ONET.XML file. Step 2: Reset IIS on the SharePoint server. On the SharePoint server type iisreset on the command line and wait for IIS to reset. Step 3: Create a new SharePoint site based on the Site Definition you added the Feature to. Open Internet Explorer. Browse to the http://SharePointServerName/SiteDirectory/ site. Click Create Site In the Title and URL Name textboxes enter CustomDocLibViewOnHomePage In the Template Selection area of the web page click the Custom Site Definitions tab and select the Sample Site template. Click the Create button. You will see the Custom Document Library on the home page!