Friday, February 15, 2008

Creating a Custom Site Definition from an existing Site (template) : Part 1

The msdn here and other blogs are talks about creating a site definition from an existing site definition. Some time or most of the time we need to create a site definition from en existing (running) site, with all the modification done in the site. For example we may modified the home page, introduced new custom lists, include other asp pages. So there should be a way to do this.

In this post i will create a site definition from an existing (running) site. This example takes a Blank Site, but this can be applied to any site like Team Site.

  1. Create a blank site using “Blank Site” Template with default settings
  2. To make it simple don’t modify anything and introduce new list.
  3. Generate the site definition (source) from the newly created site, using Sharepoint Solution Generator.
  4. The solution generator creates the .csproj file Site Definition and other folder.
  5. Create a folder called CustomBlankSiteSource, this contains all the source to generate our new custom site definition
  6. We need to create a folder structure as same site template folder structure, so create a folder called 12. Inside this folder create two sub folder namely, 1033 & SiteTemplates
  7. In the 1003 folder we created above, create a folder called, xml.
  8. In the SiteTemplate folder we created above, create a folder called CustomBlankSite. This folder should be map with our new site definition name.
  9. Create a folder, xml inside the CustomBlankSite folder.
  10. Now create a xml template for the new custom site definition as follows.
   1:  <?xml version="1.0" encoding="utf-8"?>

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

   3:  <!-- _LocalBinding -->

   4:  <Templates xmlns:ows="Microsoft SharePoint">

   5:   <Template Name="CustomBlankSite" ID="10005">

   6:      <Configuration ID="1" Title="Customized Blank Site" Hidden="FALSE" ImageUrl="/_layouts/images/blankprev.png" Description="A customized blank site to experiment site definition from Site Template (existing site)" DisplayCategory="Custom Site Definitions" AllowGlobalFeatureAssociations="False" >    </Configuration>

   7:   </Template>

   8:  </Templates>
  1. Note the template name in the above xml. This name and the folder name inside the site template should be same.
  2. The id value can be anything above 10000. Refer this msdn for further info for this id.
  3. Name this xml file as WEBTEMP_CustomBlankSite.XML and place it in CustomBlankSiteSource\12\Template\1033\XML folder.
  4. Now we have to define the whole site definition.
  5. Copy the default.aspx from the Site Definition folder, generated by the Solution Generator and place it in CustomBlankSiteSource\ 12\Template\SiteTemplates\CustomBlankSite folder.
  6. Open the onet.xml from the Site Definition folder, generated by the solution generator, and remove the AllUsersWebpart. Then copy the AllUsersWebpart from the onet.xml resides in the 12hive\TEMPLATE\SiteTemplates\sts\xml folder. There are more than one AllUsersWebpart, and you can copy from anyone. Change the image url, if you want your custom image.
  7. So now your folder and file structure looks like this.


  1. Place the wspbuilder.exe and cablib.dll inside the CustomBlankSiteSource folder.
  2. Now execute the wspbuilder from command prompt. Make sure that you are inside CustomBlankSiteSource folder in the command prompt.
  3. This creates the CustomBlankSiteSource.wsp. if you want you can use give other name as parameter to the wspbuilder.
Now you have a site definition which is created from an existing site. You can stsadm to add and deploy the solution.

The next article talks about adding default list like links, tasks, and custom list specific to our site definition.[Tips: The custom list is based on the Post list available in the blog site definition]

[update]
Download the sample code from here.

Cheers,
Murugan G.

References:

No comments: