SPWeb.ApplyWebTemplate 方法 (SPWebTemplate)
Applies the specified site definition object or site template object to the website that has no template applied to it.
命名空间: Microsoft.SharePoint
程序集: Microsoft.SharePoint(位于 Microsoft.SharePoint.dll 中)
语法
声明
Public Sub ApplyWebTemplate ( _
webTemplate As SPWebTemplate _
)
用法
Dim instance As SPWeb
Dim webTemplate As SPWebTemplate
instance.ApplyWebTemplate(webTemplate)
public void ApplyWebTemplate(
SPWebTemplate webTemplate
)
参数
webTemplate
类型:Microsoft.SharePoint.SPWebTemplateThe site definition or site template to be applied.
异常
异常 | 条件 |
---|---|
ArgumentNullException | webTemplate is null . |
备注
This method calls the ApplyWebTemplate(String) method with the Name property of the webTemplate parameter.
警告
Be careful about calling this method within a website provisioning callback function. If you call this method inside a provisioning callback function that is defined within the same site definition configuration that is being applied, you can cause an infinite loop. Instead, create two similar site definition configurations within the site definition, one that is visible and one that is hidden. The configuration can then contain a provisioning assembly callback function that applies the hidden configuration to websites.
示例
The following code example applies a specified site template object to a subsite in the current site collection.
Dim siteCollection As SPSite = SPContext.Current.Site
Using webSite As SPWeb = siteCollection.OpenWeb("Website_URL")
Dim webTemplates As SPWebTemplateCollection =
siteCollection.GetCustomWebTemplates(Locale_ID)
Dim webTemplate As SPWebTemplate = webTemplates("Template_Name")
webSite.ApplyWebTemplate(webTemplate)
End Using
SPSite oSiteCollection = SPContext.Current.Site;
using(SPWeb oWebsite = oSiteCollection.OpenWeb("Website_URL"))
{
SPWebTemplateCollection collWebTemplates = oSiteCollection.GetCustomWebTemplates(Locale_ID);
SPWebTemplate oWebTemplate = collWebTemplates["Template_Name"];
oWebsite.ApplyWebTemplate(oWebTemplate);
}
备注
Certain objects implement the IDisposable interface, and you must avoid retaining these objects in memory after they are no longer needed. For information about good coding practices, see Disposing Objects.