In SharePoint you can limit the site templates the site templates that are available to users when they create a subsite. To do this you navigate to the page "Page layouts and site templates" from the site settings. For WSS there is no link to the UI to do this. You can limit the templates by manually entering the URL to the AreaTemplateSettings.aspx page.
In code there are 2 ways to do it. You can make a template available for all languages that are installed on the SharePoint server, or you can make it available just for a specific lanugage. The examples below show you how to do this, both for a publishing site and for a teamsite.
Example 1
This code snippet forces the users of our site to just use the "Team Site" template. The team site will be available in any language installed on the server. The code first finds the template using the GetWebTemplates of our SPSite object. To make it available for all languages, we use the method SetAvailableCrossLanguageWebTemplates.
This example works for both publishing sites and team sites. Although team sites do not have the site settings link to this, you can limit the number of available site templates by using the same method as on a publishingweb. You will have to set one of the properties in the property bag of the SPWeb to make it work.
using (SPSite site = new SPSite("http://moss/news"))
{
using (SPWeb web = site.OpenWeb())
{
// Find the Team Site template.
SPWebTemplate templateToAdd = null;
foreach (SPWebTemplate template in site.GetWebTemplates(web.Language))
{
if (string.Compare("STS#0", template.Name, true) == 0)
{
templateToAdd = template;
break;
}
}
if (templateToAdd != null)
{
// Create a new collection of available templates
Collection<SPWebTemplate> templates = new Collection<SPWebTemplate>();
templates.Add(templateToAdd);
// Update the web and save the changes
if (PublishingWeb.IsPublishingWeb(web))
{
PublishingWeb publishingWeb = PublishingWeb.GetPublishingWeb(web);
publishingWeb.SetAvailableCrossLanguageWebTemplates(templates, false);
}
else
{
web.SetAvailableCrossLanguageWebTemplates(templates);
web.AllProperties["__InheritWebTemplates"] = false.ToString();
web.Update();
}
}
}
}
After running this, the "Page layouts and site templates" page looks like this:
Example 2
The second example does the same thing, but users are now forced to use the Dutch Team Site template. Instead of using SetAvailableCrossLanguageWebTemplates, we now use SetAvailableWebTemplates:
using (SPSite site = new SPSite("http://moss/news"))
{
using (SPWeb web = site.OpenWeb())
{
// Find the Team Site template.
SPWebTemplate templateToAdd = null;
foreach (SPWebTemplate template in site.GetWebTemplates(1043))
{
if (string.Compare("STS#0", template.Name, true) == 0)
{
templateToAdd = template;
break;
}
}
if (templateToAdd != null)
{
// Create a new collection of available templates
Collection<SPWebTemplate> templates = new Collection<SPWebTemplate>();
templates.Add(templateToAdd);
// Update the web and save the changes
if (PublishingWeb.IsPublishingWeb(web))
{
PublishingWeb publishingWeb = PublishingWeb.GetPublishingWeb(web);
publishingWeb.SetAvailableWebTemplates(templates, 1043, false);
}
else
{
web.SetAvailableWebTemplates(templates, 1043);
web.AllProperties["__InheritWebTemplates"] = false.ToString();
web.Update();
}
}
}
}
After running this sample, the "Page layouts and site templates" page looks like this:
