共用方式為


SPWeb.ApplyWebTemplate method (String)

會指定的站台定義] 或 [網站範本套用到不已套用到任何範本的網站。

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)

Syntax

'宣告
Public Sub ApplyWebTemplate ( _
    strWebTemplate As String _
)
'用途
Dim instance As SPWeb
Dim strWebTemplate As String

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

參數

  • strWebTemplate
    Type: System.String

    網站定義或要套用的 [網站] 範本的檔案名稱的名稱。

Exceptions

Exception Condition
SPException

網站是寫入鎖定或唯讀。

備註

注意

請小心有關呼叫這個方法內的網站佈建回呼函式。如果您呼叫這個方法內定義在相同的站台定義組態所套用的佈建回呼時,您可能會造成無限迴圈。相反地,建立兩種類似站台定義的組態中的站台定義,另一個則是看得見,一個隱藏的。看得見的組態可以再包含佈建的組件回呼,會隱藏的設定套用至網站。

Examples

下列程式碼範例會將指定的站台範本套用至目前的網站集合中的子網站。

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");
}
注意事項注意事項

某些物件實作IDisposable介面,並且您必須避免之後不再需要保留這些物件在記憶體中。良好的程式碼撰寫方式的相關資訊,請參閱Disposing Objects

請參閱

參照

SPWeb class

SPWeb members

ApplyWebTemplate overload

Microsoft.SharePoint namespace