Share via


Using Modules to Add Files to a Site Definition

You can specify files to include as part of a site definition by using modules within the ONET.XML file for the site definition. Use the Modules element within a Configuration element to declare modules, and then use the Modules element outside the configuration to define the URL of any file to include as part of the definition.

Warning  It is required that you create a custom site definition by copying an existing site definition, rather than modifying the original ONET.XML file installed with Windows SharePoint Services. Changes that you make to the originally installed file may be overwritten when you install updates or service packs for Windows SharePoint Services, or when you upgrade an installation to the next product version. For information on creating a custom site definition, see Creating a Site Definition from an Existing Definition.

The following example from ONET.XML illustrates how to declare a module.

<Configurations>
   <Configuration ID="0" Name="Default">
      <Lists>
         <List Title="Shared Documents" Url="Shared Documents"
            QuickLaunchUrl="Shared Documents/Forms/AllItems.aspx" Type="101" />
         <List Title="General Discussion" Url="Lists/General Discussion"
            QuickLaunchUrl="Lists/General Discussion/AllItems.aspx" Type="108" />
         <List Title="Announcements" Type="104" Url="Lists/Announcements" />
         <List Title="Links" Type="103" Url="Lists/Links" />
         <List Title="Contacts" Url="Lists/Contacts"
            QuickLaunchUrl="Lists/Contacts/AllItems.aspx" Type="105" />
         <List Title="Events" Type="106" Url="Lists/Events" />
         <List Title="Tasks" Url="Lists/Tasks"
            QuickLaunchUrl="Lists/Tasks/AllItems.aspx" Type="107" />
         <List Title="Site Template Catalog" Type="111"
            Url="_catalogs/wt" RootWebOnly="TRUE" />
         <List Title="Web Part Catalog" Type="113" Url="_catalogs/wp"
            RootWebOnly="TRUE" />
         <List Title="List Template Catalog" Type="114" Url="_catalogs/lt"
            RootWebOnly="TRUE" />
      </Lists>
      <Modules>
         <Module Name="Default"/>
      </Modules>
   </Configuration>
</Configurations>

In the example, the "Default" module is identified as part of the configuration for the site definition.

In the Modules element, the following module definition specifies the Web Parts used on the home page in the Default module.

<Modules>
   <Module Name="Default" Url="" Path="">
      <File Url="default.aspx" NavBarHome="True">
         <View List="104" BaseViewID="0" WebPartZoneID="Left"/>
         <View List="106" BaseViewID="0" 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=11.0.0.0, Culture=neutral,
               PublicKeyToken=71e9bce111e9429c</Assembly>
               <TypeName>Microsoft.SharePoint.WebPartPages.ImageWebPart</TypeName>
               <FrameType>None</FrameType>
               <iwp:ImageLink>_layouts/images/homepage.gif</iwp:ImageLink>
               </WebPart>]]>
         </AllUsersWebPart>
         <View List="103" BaseViewID="0" WebPartZoneID="Right" WebPartOrder="2"/>
         <NavBarPage Name="Home" ID="1002" Position="Start"></NavBarPage>
         <NavBarPage Name="Home" ID="0" Position="Start"></NavBarPage>
       </File>
    </Module>
</Modules>

Any Web site instantiated from the site definition includes whatever files are specified in this module. In this example, a module for the home page is defined. Each View element within the module represents a List View Web Part, including the list that is displayed in the Web Part and how the Web Part is positioned on the page. For the left Web Part zone, this module specifies two List View Web Parts for the Announcements and Events lists, and for the right zone, it specifies an Image Web Part containing the image used on home pages and a List View Web Part for the Links list. The NavBarHome attribute specifies that this page will serve as the destination page for the Home link in the top navigation bars of sites that are created.