Modify and repackage SharePoint STP files

There have been a few occassions where SharePoint site templates (STP files) we’ve been using in client environments suddenly would stop working after upgrading WSP files, notably after removing certain features from the WSPs. Whenever you’d create a new site based on such a template, you get an error saying “The template you have chosen is invalid or cannot be found”.

Now you’d think you could fix this by just creating a new STP file based on your template site, which then wouldn’t include the feature. However, I’ve encountered cases where this error would still occur. There is a little trick you can use to remove the missing features from the STP file. This is also useful when you receive a non-working STP file from for example a client who has a different environment (extra features) than your own.

The idea is to extract the STP file, remove the missing features from the manifest and repackage the file. In order to do this, use the following steps.

Since an STP file is just a renamed cabinet file, you can just extract its contents by using a ZIP client. Copy the file to your target environment on which you’re trying to use the template.

Create a temporary folder anywhere on your system. Rename the file to .cab and extract the contents to the folder you just created. Navigate to the folder and open the manifest.xml file in a text editor.

Now, in the manifest file, you should see the following elements:

<WebFeatures>

<SiteFeatures> (I believe this one is optional though)

There should be a list of <Feature /> elements in each of these blocks. You can probably safely skip the features with GUIDs starting with 00bfea as these are SharePoint out-of-the-box features.

For any of the other feature GUIDs, you need to verify that they actually exist in your target environment. I’m not sure if there is any quick way to get an overview of all feature GUIDs in a farm, so here’s the convoluted way. Go to the following folder:

C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE\FEATURES

For each of the feature GUIDs, search in *.xml files and use the following search phrase:

ID="{GUID}"

Where {GUID} is the GUID of the elements in the manifest file.

If you can’t find a hit for a search phrase, then this is one of the features that’s not available in the environment. Remove any of these feature elements from the manifest file and save the file when done for all of the feature elements.

Repeat this process if you do have a <SiteFeatures> element in your manifest file.

Now, it’s time to repackage the contents of the cabinet file into a new STP file. Windows comes with a utility called makecab that you can use to create a cabinet file from files in a directory. The only thing is, you need a DDF file as an input parameter.

In your temporary folder you created earlier, create a new text file and name it files.ddf and open this file in a text editor. Add the following text to the file:

.OPTION EXPLICIT
.Set CabinetNameTemplate=newtemplate.stp
.set DiskDirectoryTemplate=CDROM
.Set CompressionType=MSZIP
.Set UniqueFiles="ON"
.Set Cabinet=on
.Set DiskDirectory1=.
.Set CabinetFileCountThreshold=0
.Set FolderFileCountThreshold=0
.Set FolderSizeThreshold=0
.Set MaxCabinetSize=0
.Set MaxDiskFileCount=0
.Set MaxDiskSize=0

This will basically instruct makecab to construct a new file called newtemplate.stp with a couple of settings. The threshold and size parameters allow for cabinet files larget than 1.5MB.

Now we need to add the files to be included to the DDF file. Open a command prompt and go to your temporary folder. Execute the following command:

dir /b

This will print a bare list of the files in the directory, very easy to copy and paste into your DDF file. Be sure to only include the following files:

manifest.xml
*.000

Your DDF should now look something like this:

.OPTION EXPLICIT
.Set CabinetNameTemplate=newtemplate.stp
.set DiskDirectoryTemplate=CDROM
.Set CompressionType=MSZIP
.Set UniqueFiles="ON"
.Set Cabinet=on
.Set DiskDirectory1=.
.Set CabinetFileCountThreshold=0
.Set FolderFileCountThreshold=0
.Set FolderSizeThreshold=0
.Set MaxCabinetSize=0
.Set MaxDiskFileCount=0
.Set MaxDiskSize=0

00000000.000
01000000.000
10000000.000
11000000.000
15000000.000
21000000.000
25000000.000
31000000.000
35000000.000
40000000.000
50000000.000
60000000.000
70000000.000
90000000.000
b1000000.000
c0000000.000
c1000000.000
d0000000.000
f0000000.000
g0000000.000
h0000000.000
k0000000.000
p0000000.000
q0000000.000
r0000000.000
s0000000.000
u0000000.000
u4000000.000
v0000000.000
v4000000.000
w4000000.000
x4000000.000
z4000000.000
manifest.xml

Save the file and go back to your command prompt. Execute the following command:

makecab /f files.ddf

When it’s done, go back to the temporary file where you should now see your newtemplate.stp file.

Upload this file to your SharePoint site collection and test whether you can now create a new site based on this template. If all went well, your template should be working now!

Be Sociable, Share!

One thought on “Modify and repackage SharePoint STP files

  1. Pingback: SharePoint 2010 list items: re-ordering.David Nguyen

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">