I’ve recently had to finally take a look at Site Definitions after always taking the approach of creating a blank site and using Features to build up a site.
03/31/2009 20:32:52.05 Quest.PowerGUI.ScriptEditor.exe (0x102C) 0x11B0 Windows SharePoint Services General 8e27 Medium Ensuring module folder _catalogs/masterpage
03/31/2009 20:32:52.13 Quest.PowerGUI.ScriptEditor.exe (0x102C) 0x11B0 Windows SharePoint Services Topology 95ks Critical The site /sites/InfoNetDev could not be created. The following exception occured: File or arguments not valid for site template 'CustomPortalTemplate#0'..
The issue I was having was that I could create the Site Collection using Central Administration, but when I tried to create the site collection using the object model in PowerShell it was throwing the above error!
The reason I wanted to do this was so that I could use automated scripts to setup and tear down the Site Collection…not a big fan of the web UI for speed ;-)
function create-spsite ([String] $url, [String] $OWNERACCOUNT, [String] $OWNEREMAIL)
$uri = new-object -TypeName System.Uri -ArgumentList "$url"
$exists = ([type]"Microsoft.SharePoint.SPSite")::Exists($uri);
"Deleting Staging SPSite"
$site = new-object -TypeName "Microsoft.SharePoint.SPSite" -ArgumentList "$uri";
$webApplication = ([type]"Microsoft.SharePoint.Administration.SPWebApplication")::Lookup($uri);
$webApplication.Sites.Add($uri, "InfoNet", "", 1033, "PortalPortalCollection#0", $OWNERACCOUNT, "owner", $OWNEREMAIL);
I tried to ensure that the Web Templates were in there, using GetWebTemplates() command. The PowerShell was as follows:
$globalAdmin = New-Object -TypeName "Microsoft.SharePoint.Administration.SPGlobalAdmin";
$webTemplates = $globalAdmin.VirtualServers.GetWebTemplates("1033");
$webTemplates | Select Name, Description;
But the problem was it wasn’t returning my Site Definitions or Site Templates back!
I left it for the night and came back to it this morning. When I started up my VMs, I ran this command again it showed the Templates. Then when I ran the code to create the site collection using the Object Model it worked too! I didn’t change any of the webTemp.xml files or the site definition xml files either!
There are “remarks'” on the SPSite.GetWebTemplates MSDN page that highlights issue with calling the templates if they have only just been installed by a Solution Package, thanks to @paulschaeflein for pointing me to this URL. I’d also like to thank @AndrewWoody, @flarepoint, @toddklindt and @keutmann for also firing back a few quick answers as I came across things yesterday evening.
So what I ended up doing was creating the site collection via stsadm as recommended in the remarks and firing an IISRESET before calling it:
stsadm -o createsite -url $webappUrl -owneremail $OWNEREMAIL -ownerlogin $OWNERACCOUNT -lcid "1033" -sitetemplate "CustomPortalCollection" -title "InfoNet"
Then I just removed the create-spsite powershell function for good measure! The reason this works is that stsadm is fired on another thread and picks up the new Site Templates.
So, some of the key things I took away from this (which will end up on the SharePointDevWiki.com shortly):
- always IISRESET when modify any files in the 12 Hive
- bear in mind that sometimes the Central Admin and Site User Interface is more forgiving than object model – thanks to @AndrewWoody for his account on his findings!
- don’t forget your own social bookmarks you’ve collected over the last 3 years on Site Definitions!
- the webtemplate paramter used in SPSite.Add() is a combination of the <Template> Name and the <Template><Configuration> Id attributes
So my first real customisation experience with Site Definitions has left me bitter and twisted, but not defeated!