SharePoint Site Definition for Multiple Subsites Creation

By:   |   Comments   |   Related: > SharePoint Configuration


Problem

The requirement of creating multiple SharePoint sub sites automatically, at one time, comes up at most organizations. You would think this would be really complex since it requires you to inherit SPWebProvisioningProvider, override its Provision function and do C# coding. This approach does involve a good amount of time and effort, but there is a better way which will save time writing code and will work seamlessly.

Solution

The solution lies in exploring the (out of the box ) Site Definition for Site Collection!

You must have noticed that a site collection provisions with its sub sites. For example: a Collaboration portal would come with sub sites for News and Search. A little bit of research on how it is done reveals the steps for creating a site definition which will create a site and its sub sites automatically.

To try our approach, let’s create a publishing site (BLANKINTERNET#0 site definition) with three sub sites namely:

  • a. News Site using (SPSNEWS#0 site definition)
  • b. Press Releases site (BLANKINTERNET#1 site definition)
  • c. Team Site (STS#1 site definition)

To get the full list of site definition IDs, read here.

Follow the below steps:

1) Go to 12 \Template\XML (MOSS 2007) Or 14\Template\XML (SharePoint 2010)

2) Create an XML file (let’s say subwebs.xml). Open the file and paste the below text:

<?xml version="1.0" encoding="utf-8" ?>
<portal xmlns="PortalTemplate.xsd">

<!—Write you Custom site and subsite info here -->

    <web name="BlankInternet Site" 
         siteDefinition="BLANKINTERNET#0" 
        displayName="BlankInternet Site" 
        description="It has three subwebs" >
        <webs>
            <web name="News site" 
              siteDefinition="SPSNEWS#0" 
              displayName="News site" 
              description="subweb 1" />

            <web name="Press Releases site" 
                siteDefinition="BLANKINTERNET#1" 
                displayName="Press Releases site" 
                description="subweb 2" />
         
            <web name="Team site" 
                siteDefinition="STS#1" 
                displayName="Team site" 
                description="subweb 3" />
        </webs>
   </web>
</portal>

You can change the sitedefinition, displayName and description of the sites based on which sites you want to provision.

3) Now you need to create the WEBTEMP file just like usual site definition. Go to:

  • 12\Template\1033\XML (MOSS 2007)
  • or 14\Template\1033\XML (SharePoint 2010)

4) Create webtempSUBWEBS.xml (the name should always start with webtemp. That’s how SharePoint recognizes it internally)

5) Paste the below text in this xml:

<?xml version="1.0" encoding="utf-8"?>
<!-- _lcid="1033" _version="12.0.4518" _dal="1" -->
<!-- _LocalBinding -->

<Templates xmlns:ows="Microsoft SharePoint">

 <Template Name="SUBWEBS" ID="84529"> 
 <!—Give a unique Template ID and Name above -->
 
    <Configuration
              ID="0"
              Title="Team Site with sub webs"
<!--You can change title to whatever you want your site name to be-->

              Hidden="FALSE"
              ImageUrl="/_layouts/images/officialfile.jpg"
              Description="This template creates a BLANKINTERNET site with 3 
                subwebs: a news site, a press releases site and a team site"
              ProvisionAssembly="Microsoft.SharePoint.Publishing, Version=12.0.0.0,
                Culture=neutral, PublicKeyToken=71e9bce111e9429c"
              ProvisionClass="Microsoft.SharePoint.Publishing.PortalProvisioningProvider"

              ProvisionData="xml\\subwebs.xml"
<!—ProvisionData tells SharePoint where to find the configuration information
    for the sites that need to be provisioned-->

              DisplayCategory="Custom"
<!—Your site definition will appear under CUSTOM heading when you create new site-->
              >
    </Configuration>

 </Template>

</Templates>

6) The ProvisionData parameter tells SharePoint to go to subwebs.xml which we created (in step 2 above) for site information.

7) Restart the web server (with IISRESET).

8) That’s it!

Now let's create a new site to test our site definition

title and description
Figure 1

As you see in Figure 1, when you create a new site or site collection, you will see our new site definition under CUSTOM category in Template selection

adventure works
Figure 2

As you can see in Figure 2, our site got created with three sub sites.

team site
Figure 3

As shown in Figure 3 above, the ‘Team site with sub webs’ site got created with three sub sites:

‘News site’, ‘Press Releases site’ and ‘Team site’

The name and description of the site and it's subsites are what we mentioned in our subwebs.xml file.

For using other out of box site definitions or even custom site definitions, use the custom site definition ID in  the above mentioned link.

Next Steps
  • Create a site with sub webs using the above method.
  • You can read more on spwebprovisingprovider here.


sql server categories

sql server webinars

subscribe to mssqltips

sql server tutorials

sql server white papers

next tip



About the author
MSSQLTips author Shishir Bhandari Shishir Bhandari

This author pledges the content of this article is based on professional experience and not AI generated.

View all my tips



Comments For This Article

















get free sql tips
agree to terms