Gorgo.Live.ToString()

Mariusz, Gorzoch tech Blog

Be carefull with “Save site as template”

leave a comment »

Few days ago I was fighting with creating custom template and later on trying to query all sites build based on that template. Sound easy as what you need to do is in the most simple way iterate thru all sites in your root web and just check what is the "TemplateID". Based on that you can browse/present for the user all sites build with use of particular template ID. So, what is tricky part ? The tricky part is that when you are using "Save site as template" functionality of SharePoint UI you will always get template ID equal to the template ID of template site used to as base for you site template. If you don’t change this ID somehow, then you will end up with quering not only sites build on your template, but also sites build on the parent template used for building your template.
 
 
the question is if we can do something about that ?
 
as you can imagine, of course we CAN !
 
When you save your "custom template" it goes with extension ".stp". This file is nothing else as "CAB" file, so we can get and dig into it. First, we need to extract it content to some dictionary. To do so, we can use "WinZip" (just change extension of the file to ".cab" and open it with "WinZip"). After extraction we should find there file with name : manifest.xml. Now you need to open this file in edit mode and look for the tag "<TemplateID>"
 
 
to change ID of the template you need to replace the current value inside <TemplateID></TemplateID> with your custom value. Personally I suggest to peak some value above 30000.
 
Now, save and exit.
 
Ok, we are almost done, now we need to pack our solution again back to .stp. To do this, we need to use "MakeCab" tool. Before we go and use it, we need to prepare script "ddf" file. This file is nothing else like a text file, which contain list of files to be packed inside "cab". In my case my orginal ".stp" file contain of 5 files:
 
– 53000000.000
– f2000000.000
– g2000000.000
– h2000000.000
– manifest.xml (this one was changed with new TemplateID)
 
All those files need to be puted in "ddf" file, where each one is placed in separete line.
 
if you done this, then now what you need to do is nothing else like call "MakeCab" to create our "cab" file. To do so we need to issue cmd: "MakeCab /F <our.ddf>". When you do this, you should get new directory in the place where you start the command with name "disk1". Go to this directory and you should find your cab file. Now you need to rename it to ".stp" and you are ready to go ! ! !
 
use stsadm -o addtemplate -filename <your stp file> -title <your template title>
 
and your template is back again in sharepoint. Now if you create some sites based on it, you can be sure that they will have their own new ID, choisen by you during editing "manifest.xml" file.
 
Advertisements

Written by Mariusz Gorzoch

22 June 2009 at 21:05

Posted in SharePoint

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: