Saturday, April 19, 2008

Custom Site Definition

Here are the steps to create a custom site definition:

1. Create a Class Library in VS2008, name it CustomSite
2. Since WSPBuilder will be used to create the wsp for this, we need to create the folder structure which is gonna match what WSPBuilder needs to put this into the 12 hive.
3. In the root of Solution Explorer, create a folder structure like the following and use the existing files in the 12 hive as a starting point:

  • 12
      • 1033
        • XML
          • WEBTEMP.XML (copied from 12\TEMPLATE\1033\XML)
      • IMAGES (add the logo file for this site definition)
      • SiteTemplates
        • CUSTSITE
          • default.aspx (copied from 12\TEMPLATE\SiteTemplates\sts)
          • XML
            • ONET.XML(copied from 12\TEMPLATE\SiteTemplates\sts\xml)
4. Rename WEBTEMP.XML to WEBTEMPCUST.XML, open to edit it.
5. The completed WEBTEMPCUST.XML will look like this:

<?xml version="1.0" encoding="utf-8"?>

<!-- _lcid="1033" _version="12.0.4518" _dal="1" -->

<!-- _LocalBinding -->

<Templates xmlns:ows="Microsoft SharePoint">

<Template Name="CUSTSITE" ID="2008">

<Configuration ID="0"

Title="Custom Site"



Description="A custom site definition."





6. Now right click the project in VS, go to properties => Build Events => Put the following in the Post-build Event Command Line:

cd $(ProjectDir)

stsadm -o retractsolution -name CustomSite.wsp -immediate

stsadm -o exeadmsvcjobs

stsadm -o deletesolutioin -name CustomSite.wsp

stsadm -o addsolution -filename CustomSite.wsp

stsadm -o deploysolution -name CustomSite.wsp -immediate

stsadm -o exeadmsvcjobs

7. Go ahead and build the solution.

8. You can take a look at the manifest.xml which is created by the wspbuilder:

<?xml version="1.0" encoding="utf-8"?>

<Solution xmlns:xsi=""





<SiteDefinitionManifest Location="CUSTSITE">

<WebTempFile Location="1033\XML\WEBTEMCUST.XML" />




<TemplateFile Location="IMAGES\logo.gif" />



9. In the above manifest.xml, note that the SiteTemplates tree which contains the ONET.XML is not included in the manfiest.xml. You don't have to include that in the manifest.xml, it just works.

10. Go to Central Administration => Operations => Under Global Configuration => Solution Management => you can see that the customsite.wsp is in the solution list of the farm.

11. Go to Application Management => Under SharePoint Site Management => Create site collection => Under Select a template => you can see the 'Custom' site defintion we've created => click the tab, you can see the 'Custom Site' template as well as the logo and description we've defined in the WEBTEMPCUST.XML

12. Go ahead and create the site collection. Click the link to link to the top-level site. Since we are using the ONET.XML of the team site and we include the default.aspx of the team site, the result is exactly the same as creating a new team site.

13. Go to Site Action => Create => Under Web Pages => Sites and Workspaces => once again the Custom tab will be available under Select a template section, so a site definition can be used to create a top-level site as well as a site within the site collection.

blog comments powered by Disqus