Click to Rate and Give Feedback
MSDN
MSDN Library
Web Development
SDK Documentation
SPWeb Class
SPWeb Methods
 ApplyWebTemplate Method (String)

  Switch on low bandwidth view
Community Content
In this section
Statistics Annotations (0)
SPWeb.ApplyWebTemplate Method (String) (Microsoft.SharePoint)
Applies the specified site definition or site template to the Web site that has no template applied to it.

Namespace: Microsoft.SharePoint
Assembly: Microsoft.SharePoint (in microsoft.sharepoint.dll)
Visual Basic (Declaration)
Public Sub ApplyWebTemplate ( _
    strWebTemplate As String _
)
Visual Basic (Usage)
Dim instance As SPWeb
Dim strWebTemplate As String

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

Parameters

strWebTemplate

A string that contains the name of the site definition or the file name of the site template, including the .stp extension.

CautionCaution:

Be careful about calling the ApplyWebTemplate method within a Web site 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 Web sites.

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

Visual Basic
Using webSite As SPWeb = SPContext.Current.Site.OpenWeb("Website_URL")
    webSite.ApplyWebTemplate("File_Name.stp")
End Using
C#
using (SPWeb oWebsite = SPContext.Current.Site.OpenWeb("Website_URL"))
{
    oWebsite.ApplyWebTemplate("File_Name.stp");
}
NoteNote:

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 Best Practices: Using Disposable Windows SharePoint Services Objects.

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Specifying Configuration IDs      LZandman   |   Edit   |   Show History

Note that you can also append the configuration ID to the site definition name, like this:

    oWebsite.ApplyWebTemplate("STS#1");  // Blank site

or...

    oWebsite.ApplyWebTemplate("STS#2");  // Document Workspace

Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker