Friday, January 2

Creating a Site Definition from an Existing Site Definition:

This task involves use of Collaborative Application Markup Language (CAML) in two schema files:

1) a copy of a WEBTEMP.XML file
2) copy of an ONET.XML file

It is recommended to make modifications only on the copy of WEBTEMP.XML and ONET.XML but on actual one. Steps to do this task are following:

1) Copy any of the existing site definition folder located in the C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\SiteTemplates directory and paste it there itself. Consider if you are going to extend the definition of Team Site then you need to copy the “sts” folder and paste it with your custom site definition name. Let it be ‘Projecttemplate’

2) Make a copy of the WEBTEMP.XML file located at Local_Drive:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE\1033\XML. Give the file a unique name by appending a string to the name of the original file; for example, WEBTEMPACTION.XML. At run time, the compiler merges information contained in this file with the information contained in the original file in order to specify which site templates are available for creating new sites.

Important: The naming convention is mandatory here and you need to name your custom webtemp.xml file in the following format WEBTEMP*.xml. (The SharePoint looks for the configuration inside the files which starts with WEBTEMP)

3) Customize the contents of the new WEBTEMP file. Each WEBTEMP.XML file contains a collection of Template elements and Configuration sub elements, which identify to the compiler all the site definitions that can be instantiated. The Configuration element defines a title, a description, and a URL for the image displayed in the user interface, properties common to each Web site created using the site definition.

Important: In custom WEBTEMP*.xml file you need to mention the custom site definition template folder name (here it is Projecttemplate’) and need to mention the ID for it. The ID should be greater than 10000 (from 1-10000 it was reserved by Microsoft for the default site definitions).

4) You can mention any number of configuration per template provided you need to mention the contents for every configuration in the ONET.XML file.

5) Delete the code in between tag and add the following:




TEMPLATE Element:

• The Name attribute must match your site definition folder name. It must match the name exactly and it is case sensitive. Use UPPERCASE.

• The ID attribute must be unique and greater than 10,000.

CONFIGURATION Element

ID is required and specifies a unique ID for the configuration.

Title is the name that appears on the Template Selection page. Your custom site definitions will appear under the default SharePoint list of Team Site, Document Workspace, etc.

Type is optional and identifies the configuration with a specific site definition.

Hidden specifies whether the site configuration appears as an option on the Template Selection page in SharePoint.

ImageURL is the large image you see on the Template Selection page. You can leave this as the default that SharePoint uses, or specify your own file. A way to use this would be to take a screenshot of the final site definition, create an image file suitable for the Template Selection screen, and specify that for this image so when the user is selecting a template upon site creation, they have a visual clue as to which template this one is.

Description is the text description that appears under the image on the Template Selection page. The description should describe the purpose or intended use of the template.

6) Save it

7) Reset IIS.

Now site definition is ready to use. Windows SharePoint Services merges the contents of all files that match WEBTEMP*.XML when showing available configurations on the Template Selection page. This makes it easier to install and uninstall site definitions, because their contents do not have to be merged into one WEBTEMP.XML file.

Whenever a new SharePoint site collection is created, you can get the new site template under custom tab.  

But there are some issues. If you are creating a site collection using this new site template and opening the site in SharePoint Designer then you would discover that something is missing…..; some very important things in /_catalogs/masterpage. You would notice that only default.master is present.  

It’s all about the Features. In this case, not only does the ONET.XML file determine what Features are provisioned as part of the site, there are also Features which determine what goes into a site that have nothing to do with the site itself - they are system Features that SharePoint uses when provisioning all sites.

8) To make sure that your new Site Definition has all the right pieces and parts, navigate to the \12\Template\Features\BaseSiteStapling folder and open BaseSiteStapling.xml in Notepad. It should look something like this:



9) Simply go through BaseSiteStapling.xml and each time you see an ID associated with STS#0 add an entry for ProjectTemplate.

10) You now have to do the same thing in the PremiumSiteStapling.xml file located in \12\Template\Features\PremiumSiteStapling folder.

11) If you want the included workflows, do the same in FeatureStapling.xml in \12\Template\Features\StapledWorkflows folder.

12) Reset IIS

13) Create a new Site Collection based on your custom Site Definition. Now, when you edit the site in SharePoint Designer, you will see all the right files in /_catalogs/masterpage, such as DefaultLayout.aspx, AdvancedSearchLayout.aspx, SearchMain.aspx, etc.

Happy now ???

No comments: