Creating a Custom Document Library Feature in WSS V3 / MOSS 2007
August 16, 2007
Creating a custom Site Definition in WSS V3 / MOSS
August 16, 2007

Adding a Document Library Feature to a Site Definition in WSS V3 / MOSS 2007

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:

<Configuration ID=”0″ Name=”Default”>

<Lists>

<List FeatureId=”00BFEA71-E717-4E80-AA17-D0C71B360101″ Type=”101″ Title=”$Resources:core,shareddocuments_Title;” Url=”$Resources:core,shareddocuments_Folder;” QuickLaunchUrl=”$Resources:core,shareddocuments_Folder;/Forms/AllItems.aspx” />

<List FeatureId=”00BFEA71-6A49-43FA-B535-D15C05500108″ Type=”108″ Title=”$Resources:core,discussions_Title;” Url=”$Resources:core,lists_Folder;/$Resources:core,discussions_Folder;” QuickLaunchUrl=”$Resources:core,lists_Folder;/$Resources:core,discussions_Folder;/AllItems.aspx” EmailAlias=”$Resources:core,discussions_EmailAlias;” />

<List FeatureId=”00BFEA71-D1CE-42de-9C63-A44004CE0104″ Type=”104″ Title=”$Resources:core,announceList;” Url=”$Resources:core,lists_Folder;/$Resources:core,announce_Folder;”>

<Data>

<Rows>

<Row>

<Field Name=”Title”>$Resources:onetid11;</Field>

<Field Name=”Body”>$Resources:onetid12;</Field>

<Field Name=”Expires”>&lt;ows:TodayISO/&gt;</Field>

</Row>

</Rows>

</Data>

</List>

<List FeatureId=”00BFEA71-2062-426C-90BF-714C59600103″ Type=”103″ Title=”$Resources:core,linksList;” Url=”$Resources:core,lists_Folder;/$Resources:core,links_Folder;” />

<List FeatureId=”00BFEA71-EC85-4903-972D-EBE475780106″ Type=”106″ Title=”$Resources:core,calendarList;” Url=”$Resources:core,lists_Folder;/$Resources:core,calendar_Folder;” QuickLaunchUrl=”$Resources:core,lists_Folder;/$Resources:core,calendar_Folder;/Calendar.aspx” EmailAlias=”$Resources:core,calendar_EmailAlias;” />

<List FeatureId=”00BFEA71-A83E-497E-9BA0-7A5C597D0107″ Type=”107″ Title=”$Resources:core,taskList;” Url=”$Resources:core,lists_Folder;/$Resources:core,tasks_Folder;” QuickLaunchUrl=”$Resources:core,lists_Folder;/$Resources:core,tasks_Folder;/AllItems.aspx” />

</Lists>

<Modules>

<Module Name=”Default” />

</Modules>

<SiteFeatures>

<!-BasicWebParts Feature –>

<Feature ID=”00BFEA71-1C5E-4A24-B310-BA51C3EB7A57″ />

</SiteFeatures>

<WebFeatures>

<!-TeamCollab Feature –>

<Feature ID=”00BFEA71-4EA5-48D4-A4AD-7EA5C011ABE5″ />

</WebFeatures>

</Configuration>

In the <SiteFeatures> element add the following XML to add your own custom Document Library Feature (Please see the Creating a Custom Document Library Feature in WSS V3 / MOSS 2007 article for instructions on how to create a custom Document Library Feature.):

<!-Custom Common Document Library Feature –>

<Feature ID=”<GUID OF YOUR FEATURE GOES HERE>” />

The <GUID OF YOUR FEATURE GOES HERE> portion of the XML above should be replaced with the GUID you created for your feature. This GUID is found in the ID attribute of the <Feature> element inside the Feature.xml file that corresponds to the custom Document Library Feature you are adding.

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 <Lists> element under the Configuration section we just edited, add the following XML to add your own custom Document Library Feature. (Please see the Creating a Custom Document Library Feature in WSS V3 / MOSS 2007 article for instructions on how to create a custom Document Library Feature):

<List FeatureId=”<GUID OF YOUR FEATURE GOES HERE>”

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:

<List FeatureId=”<GUID OF YOUR FEATURE GOES HERE>”

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 <Module> in the ONET.XML that is invoked by the Configuration we just edited. The XML looks like this:

<Module Name=”Default” Url=”” Path=””>

<File Url=”default.aspx” NavBarHome=”True”>

<View List=”$Resources:core,lists_Folder;/$Resources:core,announce_Folder;” BaseViewID=”0″ WebPartZoneID=”Left” />

<View List=”$Resources:core,lists_Folder;/$Resources:core,calendar_Folder;” BaseViewID=”0″ RecurrenceRowset=”TRUE” WebPartZoneID=”Left” WebPartOrder=”2″ />

<AllUsersWebPart WebPartZoneID=”Right” WebPartOrder=”1″><![CDATA[

<WebPart xmlns=”http://schemas.microsoft.com/WebPart/v2″ xmlns:iwp=”http://schemas.microsoft.com/WebPart/v2/Image”>

<Assembly>Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c</Assembly>

<TypeName>Microsoft.SharePoint.WebPartPages.ImageWebPart</TypeName>

<FrameType>None</FrameType>

<Title>$Resources:wp_SiteImage;</Title>

<iwp:ImageLink>/_layouts/images/homepage.gif</iwp:ImageLink>

</WebPart>

]]></AllUsersWebPart>

<View List=”$Resources:core,lists_Folder;/$Resources:core,links_Folder;” BaseViewID=”0″ WebPartZoneID=”Right” WebPartOrder=”2″ />

<NavBarPage Name=”$Resources:core,nav_Home;” ID=”1002″ Position=”Start” />

<NavBarPage Name=”$Resources:core,nav_Home;” ID=”0″ Position=”Start” />

</File>

</Module>

The <Module> element specifies the resources that Configurations which invoke this mode use. The <File> element specifies files that the Configuration will implement. Inside the <File> element for the default.aspx page add the following XML to create a view of the Custom Document Library list.

<View List=”$Resources:core,lists_Folder;/Custom Document Library” BaseViewID=”0″ WebPartZoneID=”Left” WebPartOrder=”3″ />  

*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:

<View List=”$Resources:core,lists_Folder;/$Resources:customDocumentLibrary,customDocumentLibrary_Folder;” BaseViewID=”0″ WebPartZoneID=”Left” WebPartOrder=”3″ />

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!