Fun with TemplateIDs in SharePoint

Today I'm taking a slight break from direct coding examples to introduce a simple topic which will be useful later when I write about customizations in SharePoint.  Don't fret though, I'll be writing about Microsoft.SharePoint.Portal next week for those of you just reading this for code.

In SharePoint, both lists and sites have the capability of being saved as a template.  You can view already saved lists in the List Template Gallery and already saved Sites in the Site Template Gallery.  When you do save a list or a site you are presented with a link to the appropriate gallery afterward.  You must go to the gallery to get a copy of that tempalte if you would like to save it to your filesystem in order to transport it elsewhere.  These templates have the extension of STP once you save them.

I sometimes see STP Templates confused with what is known as site definitions.  This is simply because site definitions are stored on the filesystem of the server under a folder called TEMPLATES.  These two things are in NO WAY the same.  They are however used together since STP Templates are essentially the delta, or difference between a specific site definition and what the site was when it was saved as an STP Template.  Think of the STP Template as paint without a canvas.  Think of the site definition as the canvas without the paint.  Put the two together, and you no longer have something everyone has, you have something unique that you have created.  This is not to say that you can't take a copy of your paint and put it on someone elses canvas (because their templateID number happens to be the same), but it would not truely be a copy of the original and their canvas may have some holes in it.  I will be writing much about site definitions in later entries (its one of my favorite topics of discussion).

For the purpose of following along with this blog, I would encourage you to save a list and a site as a template, and then save them out of their galleries to your filesystem.  Once you have them saved, rename the STP files so that they have the extension of CAB.  In the CAB file, you will find a MANIFEST.XML file.  You may see some other files, which you can ignore for now.

Open the MANIFEST.XML file in IE and let it render.  Near the top, you will see a TemplateID.  It looks like this:



You will see the TemplateID defined in both your saved Site Template and your saved List Template.

The slightly interesting thing about this is that neither of the templates are truely a "template" all by themselves.  The templateID acts as a pointer.  In the List Template, the template ID is pointing to the specific list definition (which is also defined in the XML) within the site definition identified by that same number.  In the Site Template, the template ID is simply pointing to a specific site definition in its entirety.  What the heck do I mean by all this you might be asking...

To really answer this, you have to look at some of the basics of site definitions. Here is a picture from one of my WSS only servers of my TEMPLATE\1033 folder (1033 for english of course--I have since installed the Swedish template language pack, so on my server I have a 1053 folder as well).



Note that the 1033 Template has MPS, STS, and XML.  The MPS and STS have a LISTS folder with a variety of recognizable list types.
MPS stands for meeting site, STS stands for team site.  XML is where the WEBTEMP.XML (and others) are stored to configure the site definition.

Here's the XML folder:



I specifically mentioned the WEBTEMP.XML because this ties together the initial structure of the site definition.  When we start up IIS we will look in the various template\<LANG>\XML folders for WEBTEMP*.XML and read their config into memory (SharePoint Portal adds a WEBTEMPSPS.XML if you're paying close attention you may have noted that...).  Here's what we read on the default WEBTEMP.XML:



Notice how the <Template Name is set to the corresponding folder names (these are in CAPS) in the TEMPLATE\1033 folder.  The ID number in this configuration file is what the templateID I spoke of earlier is associated with.

So if you save a document library (which yes, is a list) as a template and it has templateID of 1, you know it is sourcing the TEMPLATE\1033\STS\LISTS\DOCLIB files.  Keep in mind that when you render the document library, you will be viewing a composite of the site definition and your "delta" together.  The saved list as a STP Template is simply the "delta".  If you truely wanted a copy of a list or site using templates, you need to copy the appropriate site definition as well.

One of the things to know now that you have all this in your head is that you can't take a list based on one templateID and use it in a site based on another templateID.  You would be able to import the template and see it in the gallery, but you would not see it on the create list unless the templateID of that imported list item matches the site's templateID that the gallery is within.

This is quite a process to go through though just to look at what the value of templateID is however... so here's a trick for you.
If you modify the list gallery, you can add additional collumns to the list and view what templateID the list was originated from (much easier).  So if you're unsure what your site is, simply save a list--modify the view in your List Template Gallery and you'll get your templateID number.

posted on 2005-09-21 02:41  mmneo  阅读(1218)  评论(0编辑  收藏  举报