Quantcast
Channel: MoveSites Issue Tracker Rss Feed
Viewing all articles
Browse latest Browse all 4

Commented Issue: .WebTemplateID issues –.WebTemplateID doesn’t report what you’d think [24]

$
0
0
*** Full blog post including screenshots for this issues can be found here: http://www.sp2010blog.com/Blog/Lists/Posts/Post.aspx?ID=49 ***

Whilst in the midst of creating the new move site PowerShell script (http://movesites.codeplex.com) I needed to find out the template id of a site that has been created. For instance:
Site A was made last year and we need to move it – to do this we need to:
• Export all the content from site A (to a folder somewhere as a .cmp file )
• Find out the original site template used to create site A
• Create a new site based on the original template
• Import all the site content from the exported (.cmp) file
So as you can imagine all the above looked pretty routine for a site move – until I started to investigate the WebTemplateID property.
It would appear that this property returns the web template ID of the very FIRST template that was used to create the site, so if a site has been built on a template from previous and not from scratch then it will report the initial template id and not the current template id.
So why all the fuss?
Well, basically in the early days of SharePoint creation even Microsoft used this method to create their templates. For instance they created a blank site (STS#1) which would have the initial template ID of 1 and then (rightly so to save effort) they made the team site (STS#0) based on the blank template, but yep you’ve guessed it – the underlying WebTemplateID remained as 1… This is also the case for document workspace (STS#2) which was also based on the blank template and thus has the same initial template ID of 1.
If we list all the templates from the site collections we can see the template ID issue. To display all the templates use this code (lovingly pilfered from the excellent http://get-spscripts.com):
function Get-SPWebTemplateWithId
{
$templates = Get-SPWebTemplate | Sort-Object "Name"
$templates | ForEach-Object {
$templateValues = @{
"Title" = $_.Title
"Name" = $_.Name
"ID" = $_.ID
"Custom" = $_.Custom
"LocaleId" = $_.LocaleId
}
New-Object PSObject -Property $templateValues | Select @("Name","Title","LocaleId","Custom","ID")
}
}
Get-SPWebTemplateWithId | Format-Table


This gives us the output of:

These are all the default templates and the IDs associated with them – you can clearly see that the template names are individual BUT the web template IDs (in the end column) are grouped in to the original templates that were used to create them.
This screenshot shows the groupings of the initial template IDs:

To illustrate the issue even further I created a TEAM Site at http://sp2010blog.com/export and then ran this snippet against it:
$web = Get-SPWeb http://sp2010blog.com/export
write-host "Web Template:" $web.WebTemplate " | Web Template ID:" $web.WebTemplateId
$web.Dispose()

This returns the values of:
Web Template: STS | Web Template ID: 1
It’s clearly using the underlying site template value for a blank site…
….Still – why all the fuss? Can’t you just use the Template Name?
Well yes and no – if you are altering the script manually you can change the name manually but if you want to automate the process using a GUI for ease of use then you need to call the template ID programmatically and hence the problem… as calling the name only provides the first portion of the name (up to the #) and requires a separate call to get the id – so in essence it has to be built up, but can’t if the wrong id is reported.
The whole point of my the new move sites script is to provide a PowerShell, GUI driven script that can quickly and easily move a site from one location to another without having to edit code all the time – and more importantly do it for free rather than having to purchase very expensive third party products!
So far I haven’t been able to come up with an answer to this conundrum so anyone with any type of info or answer is more than welcome to post using the form on the right. The Move site scripts uses a drop down and link to this site for the end user to select the relevant template manually, but that is still a no go if you don’t know the source template…
One ray of sunshine however is that when you try to import a site into a newly created site made from a different template it bombs out and tells you which template you should be using in the first place which means the original template details are in there… somewhere… so if anyone has any ideas please get posting! 
Comments: ** Comment from web user: cyberprune **

You should be able to use the Configuration property of SPWeb to detect the correct WebTemplateId. See http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spweb.configuration.aspx


Viewing all articles
Browse latest Browse all 4

Latest Images

Trending Articles





Latest Images