Export (0) Print
Expand All
Expand Minimize

SPWeb.SaveAsTemplate Method

Windows SharePoint Services 3

Saves the Web site as a site template.

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

public void SaveAsTemplate(
	string strTemplateName,
	string strTemplateTitle,
	string strTemplateDescription,
	bool fSaveData
)

Parameters

strTemplateName
Type: System.String
A string that contains the internal name of the site template.
strTemplateTitle
Type: System.String
A string that contains the display name of the site template.
strTemplateDescription
Type: System.String
A string that contains the description of the site template.
fSaveData
Type: System.Boolean
true if data on the Web site is saved as part of the site template; otherwise, false.

The following code example saves the root Web site in a site collection as a custom site template.

using(SPSite oSiteCollection = new SPSite("http://localhost"))
{ 
    using(SPWeb oWebsiteRoot = oSiteCollection.RootWeb)
    {
        oWebsiteRoot.SaveAsTemplate("RootWebTemplate", 
        "Root Website Template", 
        "This is a template of the root Web site.", false);
    }
}
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.

Community Additions

ADD
Show:
© 2014 Microsoft