My subsite creation webpart lets the user choose from a list of allowable site templates. Of course, SPSiteCollections.Add() wants the internal template name, like "STS#0" for a team site template, and blog only knows what for a custom site template. My users don't like this much; they want to see "Kewl new subsite template" in the dropdown selection, so he agrees. So here's how you convert the template title to the internal name:
// We want to create the site using a pre-defined site template.
// People refer to site templates by using the public template name,
// but SharePoint refers to them by using the internal template name.
// Find the internal name for the desired site template.
string InternalTemplateName = "";
SPWebTemplateCollection webTemplates = globalAdmin.VirtualServers[0].GetWebTemplates(localid);
foreach(SPWebTemplate t in webTemplates)
{
if(t.Title.CompareTo(strPublicTemplateName) == 0)
{
InternalTemplateName = t.Name; break;
}
}
// If the template could not be found...
if( InternalTemplateName == "" )
throw new Exception( "Cannot find site template '" + strPublicTemplateName + "'." );
// Create WSS project site.
SPSite newSite = siteCollections.Add( url, title, desc, localid, InternalTemplateName, login, name, email );
Now if I can just get them all to learn binary...
0 comments:
Post a Comment