in

SharePoint Blogs

The Best Place for SharePoint-related Blogs

Todd Baginski's SharePoint 2003 and MOSS 2007 Blog

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 Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\SiteTemplates\SAMPLE\XML\ONET.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 Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\SiteTemplates\SAMPLE\XML\ONET.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 Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\SiteTemplates\SAMPLE\XML\ONET.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!

Comments

 

KnotBeer said:

I was trying to create a template file which is a Microsoft Excel 2003 document and created a directory named "Forms" (thinking since it was a form that we use) and I was going to attempt to assign this form as the template for that directory.

I have found a number of issues with this:

"Form" is reserved for WSS (that's what we use).  There is no stopping from anyone creating this, but you sure aren't ever going to delete it!

You cannot create a template for a specific directory, only for the entire "Document Library" which means even those subdirectories use the same template.  (I use the term directory because of our old DOS days, and I hate the term "Folder).

You are limited to only one template in a document library, but isn't a "LIBRARY" supposed to contain many different types of information?  Since when have you gone to a library and only seen magazines but not books???  Or books but no shelves for them to be organized on?

Microsoft is really limiting business to their standards and I really wish we could "stretch our arms" or at least organize the way the company has been for the past 19 years, which I must say, seems better than conforming to Microsoft's version of business.  (Watch "Pirates of Silicon Valley")

October 10, 2007 2:35 PM
 

Simon said:

Hi, the above is brilliantly succint but how do I put the information that makes the list feature appear as default on my new site within a feature itself (such as TeamCollab - that references other features) rather than hard coding this into the site definition onet.xml?

thanks!

Simon

October 24, 2007 11:10 AM
 

Chas said:

Have you read sharepointstudio.blogspot.com/.../document-library-template-selector.html   It tells how to setup multiple selections

October 30, 2007 1:17 PM
 

Richard said:

Fantastic series of posts, very very helpful. When I went to add the view of the custom document library to my site I got hung up for a long time though, as the post reads:

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

But actually it should be:

"<View List="Custom Document Library" BaseViewID="0" WebPartZoneID="Left" WebPartOrder="3" />"

Otherwise fantastic, thanks very much

//Rich

November 16, 2007 10:14 AM
 

Craig said:

Rich,

Actually, the inaccurate part is where the list is being created.  It should be:

<List

URL="$Resources:core,lists_Folder;/Custom Document Library" />

Accepted practice is to put lists in a Lists folder, thus:

portal/.../CustomDocumentLibrary

instead of

portal/CustomDocumentLibrary

November 26, 2007 4:36 PM
 

James said:

I am checking now the steps in adding site features to site definition. This has a connection on what I am doing right now. I am assigned to add the wiki template to the site definition. What I'm doing right now is I'm getting the feature ID on the ONET.xml of the wiki template. After that I go with the usual process of code build. Upon creating a new site, the wiki template is still not on the choices for site templates. Am I doing it right or are there additional steps in doing this?

The process must go like this:

The Wiki Template is not default in the list of templates in the subsites because it is not included in the site definition.

Once included, we could already stop doing the steps below every time we create a new site:

o        Add the Microsite Wiki Site Template (Root > Site Settings > Modify All Site Settings > Page layouts and site templates)

o        Ensure that the “Reset all subsites to inherit these preferred subsite template settings” is checked.

January 23, 2008 3:54 AM
 

Sean said:

I appreciate the information but I having a hard time understanding the definition of the some of the terms. Let me be specific: I have a require to read information of custom document properties which have been added by the client. I have used the SPFile. to return the values of properties of the document specified. I have added the SPFile.Properties (returning a hashtable) to lopp through and see all the property names and values. However I am stiil confused. Does this function allow me to return custom document properties, or how do I do that in MOSS 2007, WSS 3.0 SDK? Info is really really appreciated....

February 8, 2008 1:28 AM
 

Mark Teviotdale said:

Can you add a document library to existing sites that have been created off the definition.  Say for example i have 100 sites and want to add a document library using my feature but because of so many sites I don't want to go through them all and activate or create the library.  Is this possible using the feature technique ? as all your examples say you must create a new site for the changes to apply.

Thanks

Mark

March 3, 2008 2:24 PM
 

Obieg Dokumentow said:

I got exception during creation of site from a site template, when onet.xml contains <ListInstance OnQuickLaunch="True" />

Is there any known issue with list instance elements in onet.xml?

March 10, 2008 5:00 PM
 

Mark Brougham said:

I followed the article(s) and it worked out great. Thank you for this really helpful tutorial. I wanted to go a little step further and add a set of default folders to my document library, which I tried to do by adding <module> tags to my CustomDocLib.xml below the ListInstance section. This didn't work for me. How would this be done? my <module>s look like this:

<Module List="101" Path="Appointments" Url="Docs/Appointments" />

Many thanks if you can guide me

March 18, 2008 6:35 AM
 

Gary said:

Thanks.

April 4, 2008 12:27 PM
 

reset site definition said:

Pingback from  reset site definition

August 3, 2008 3:13 AM

Leave a Comment

(required )  
(optional )
(required )  
Add

About tbaginski

Todd began working with WSS and SPS in the beta stages of the products, in 2003. He has architected and implemented intranets, extranets, wireless deployments, and several custom applications with the WSS and SPS platforms. Todd created the first SharePoint advanced development training curriculum in the training industry for Microsoft SharePoint Portal Server 2003 and taught his first class in December of 2003. Todd also created the first advanced development training curriculum for Microsoft Office SharePoint Server (MOSS) 2007 and taught parts of this curriculum while MOSS was still in the Beta 1 Technical Refresh stage! Two versions in a row, Todd has broken ground in the training industry by being the first to offer advanced development training for SharePoint! Todd speaks at many SharePoint conferences including SharePoint Connections, the MS SharePoint Conference, and the upcoming TechEd 2008 Developers Conference. He has also spoken at Microsoft events at the Microsoft offices in both Denver, Colorado and Minneapolis, Minnesota. He has also presented several sessions at the Rocky Mountain SharePoint User's Group. He enjoys spending time with his wife and their dogs, playing and coaching lacrosse, playing hockey, riding his bike in the Rocky Mountains, and skiing every chance he gets.

Need SharePoint Training? Attend a SharePoint Bootcamp!

Posts (c) their respective authors. Everything else (c) 2007 SharePoint Experts