SPSite.GetWebTemplates Method
Returns the collection of site definitions that are available for creating Web sites within the site collection.
Namespace: Microsoft.SharePoint
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: Yes
Available in SharePoint Online
Syntax
'Declaration
Public Function GetWebTemplates ( _
LCID As UInteger _
) As SPWebTemplateCollection
'Usage
Dim instance As SPSite
Dim LCID As UInteger
Dim returnValue As SPWebTemplateCollection
returnValue = instance.GetWebTemplates(LCID)
public SPWebTemplateCollection GetWebTemplates(
uint LCID
)
Parameters
LCID
Type: System.UInt32A 32-bit unsigned integer that specifies the language of the site definitions to return from the collection.
Return Value
Type: Microsoft.SharePoint.SPWebTemplateCollection
An SPWebTemplateCollection object that represents the site definitions.
Remarks
The site definitions that are returned by the GetWebTemplates method include site definitions that are available by default, which are installed in the setup directory (\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE) of each server, and those that have been stored in the configuration database through the command-line operation stsadm -o addtemplate.
Note that in a specific scenario, the specified custom site definition is not found. This scenario occurs when the following sequence of actions occur:
Add a solution that consists of site templates and features.
Create a Web application.
Deploy the solution, including deployment of the application DLLs to the bin directory of the newly created Web application.
Create a new site collection that is based on the custom site definition that was deployed to the Web application.
When this sequence occurs, steps 1, 2, and 3 work fine, but when step 4 is called the application does not find the site definition for the newly deployed site. However, if you stop after step 3, then re-run the application and then call step 4 by itself, the proper custom site definition is found without any problems. The original problem is caused because site templates are cached when a new Web application is created. Therefore, if a custom site definition is deployed with a new Web application, it will not be found because it is not yet in the cache.
There are four ways to work around this problem.
Call all the first three steps, as described above, and then re-run the application and call only step 4. This restarts the process and allows the Web application to locate the deployed custom site definition.
Create a console application that creates a site collection using the template for the custom site definition. Then, call the sequence of four steps that are listed above; however, when you come to step 4 (create site collection), load the console executable that you created in a different process and allow it to complete step 4.
Use the Stsadm.exe command in the code itself. In this approach, the Web application is able to locate the newly deployed custom site definition.
Add and deploy the solution manually by using the SharePoint UI, or by using the Stsadm.exe command prompt.