I had to create a site definition for a blog site that I created so that it could be used as a template. My site had various custom webparts  and I also created some lists. So to incorporate all that I also used features. Here is a brief explanation of it:

Site Definitions are located in the following folder on the SharePoint server: C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\SiteTemplatesThe aspx pages and various lists that make up the site definition are stored here.Inside the xml subfolder is the onet.xml which contains the various configurations and modules of the site definition like the various web part zones in the pages.

Steps:

1.       First I traversed to C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\SiteTemplatesCopied the Blog folder and pasted it back, renamed it to SampleBlog.

2.       Next, connect the new site definition to sharepoint by copying the WEBTEMP.XML file in “C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\1033\XML” and paste it to the same location renaming it as webtempSampleblog.xml.

Open the file and delete any unnecessary <template> tag as shown below:

<?xml version=”1.0″ encoding=”utf-8″?>

<!– _lcid=”1333″ _version=”12.0.4518″ _dal=”1″ –>

<!– _LocalBinding –>

<Templates xmlns:ows=”Microsoft SharePoint”>

 <Template Name=”SampleBlog” ID=”1333″>

    <Configuration ID=”0″ Title=”Sample Blog Template” Hidden=”FALSE” ImageUrl=”/_layouts/images/BLOGPREV.PNG” Description=”Sample blog template” DisplayCategory=”Sample Templates”></Configuration>

</Template>

</Templates>

Change the name attribute to “Sample Blog Template” and the ID so that it is unique, generally numbers above 1000 will be safe.

3.       Reset IIS.

4.    Customizing the site definition.

After this point, one can see the new site definition and create new sites,but we want to customize our site definition, add various web parts etc.To do that we need to change the ONET.XML

The <Module> is created  for various pages.Inside that is <View> which represents various web part zones of the page. So, I exported the webparts and copied the xml’s in respective <View> tags representing the proper zone.

My next challenge was  with copying the xmlof DataView Web parts, as by default  Sharepoint Designer binds the control to the list instance using the list instance GUID. So, it is difficult to create a new site using this template along with the GUID’s of the DataView Web Part.

So, we need to replace the GUID’s with the list names.

i) On the attributes of the DataFormWebPart element replace the attribute ListName=”{GUID}” by ListName=”LIST_NAME” where LIST_NAME is the name of the list that you are binding to.

ii) Go through all of the DataFormParameter elements and replace:   

    <WebPartPages:DataFormParameter Name=”ListID” ParameterKey=”ListID” PropertyName=”ParameterValues” DefaultValue=”{GUID}”/>

With:

<WebPartPages:DataFormParameter Name=”ListName” ParameterKey=”ListName” PropertyName=”ParameterValues” DefaultValue=”LIST_NAME”/>

iii) Go to the ParameterBindings element and replace

    <ParameterBinding Name=”ListID” Location=”None” DefaultValue=”{GUID}”/>

With:

    <ParameterBinding Name=”ListName” Location=”None” DefaultValue=”LIST_NAME”/>   

This should give you a GUID free DataForm webpart that can be placed on a page layout used by multiple sites on your site collection (as long as the name of the list is the same on all sites).

5. IMPLEMENTING FEATURES

I had created several lists in my site, so to include those while I create a new site from my site definition, I had to use features.

To implement a feature we need to create a folder in C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES

So, I created one named SampleBlogSite, and here is the content:

<Feature Id=”67409a48-46c8-4a28-8f2e-bca0a56e4213″

  ActivateOnDefault=”False”

  Title=”Sample Blog Site”

  Scope=”Web”

  ReceiverAssembly=”Sample.Blog.FeatureDefinition, Version=1.0.0.0, Culture=neutral, PublicKeyToken=246c59317fd65cd2″

  ReceiverClass=”Sample.Blog.FeatureDefinition.FeatureListner”

  Description = “Activate this feature to convert current blog site to Sample Blogs site. this feature can only be activated to a blogs site defintion.”

  xmlns=”http://schemas.microsoft.com/sharepoint/”&gt;

</Feature>

Here, Sample.Blog.FeatureDefinition is the dll  implementing the feature.

Create a class inherited from SPFeatureReceiver. Implement the methods FeatureActivated, FeatureDeactivating, FeatureInstalled and FeatureUninstalling by overriding the base methods.

Write your code into the FeatureActivated-method.

Now change your feature.xml in the props ReceiverClass and ReceiverAssembly and set the corresponding values there for your assembly.

Refer this feature from your ONET.XML, as:

<Feature ID=67409a48-46c8-4a28-8f2e-bca0a56e4213 />

So, this completes the entire process.

Advertisements