SPWeb.ApplyWebTemplate 方法 (String)

Applies the specified site definition or site template to the website that has no template applied to it.

命名空间:  Microsoft.SharePoint
程序集:  Microsoft.SharePoint(位于 Microsoft.SharePoint.dll 中)

语法

声明
Public Sub ApplyWebTemplate ( _
    strWebTemplate As String _
)
用法
Dim instance As SPWeb
Dim strWebTemplate As String

instance.ApplyWebTemplate(strWebTemplate)
public void ApplyWebTemplate(
    string strWebTemplate
)

参数

  • strWebTemplate
    类型:System.String

    The name of the site definition or the file name of the site template to be applied.

异常

异常 条件
SPException

The website is write-locked or read-only.

备注

警告

Be careful about calling this method within a website provisioning callback function. If you call this method inside a provisioning callback 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 visible configuration can then contain a provisioning assembly callback that applies the hidden configuration to websites.

示例

The following code example applies a specified site template to a subsite in the current site collection.

Using webSite As SPWeb = SPContext.Current.Site.OpenWeb("Website_URL")
    webSite.ApplyWebTemplate("File_Name.stp")
End Using
using (SPWeb oWebsite = SPContext.Current.Site.OpenWeb("Website_URL"))
{
    oWebsite.ApplyWebTemplate("File_Name.stp");
}

备注

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.

另请参阅

引用

SPWeb 类

SPWeb 成员

ApplyWebTemplate 重载

Microsoft.SharePoint 命名空间