in

SharePoint Blogs

The Best Place for SharePoint-related Blogs

Chris Ogle's ShayuhPoint Ruminations

Deep-fried observations with a side of cooked-to-death opinions and black-eyed peas.

Convert template title to internal name

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 bog 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, and my boss doesn't even understand binary, 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...

Comments

No Comments

Leave a Comment

(required )  
(optional )
(required )  
Add

About cwogle

Thirty years of pickin' bits in the hot sun and layin' 'em in the basket for the man. Now it's time to set back on the verandah and try to make sense of this SharePoint stuff.

Need SharePoint Training? Attend a SharePoint Bootcamp!

Posts (c) their respective authors. Everything else (c) 2007 SharePoint Experts