Share via


SPList.SaveAsTemplate Method

Saves the list as a template in the list template gallery and includes the option of saving with or without the data that is contained in the current list.

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: Yes
Available in SharePoint Online

Syntax

'Declaration
Public Sub SaveAsTemplate ( _
    strFileName As String, _
    strName As String, _
    strDescription As String, _
    bSaveData As Boolean _
)
'Usage
Dim instance As SPList
Dim strFileName As String
Dim strName As String
Dim strDescription As String
Dim bSaveData As Boolean

instance.SaveAsTemplate(strFileName, _
    strName, strDescription, bSaveData)
public void SaveAsTemplate(
    string strFileName,
    string strName,
    string strDescription,
    bool bSaveData
)

Parameters

  • strFileName
    Type: System.String

    The file name for the list template with an .stp extension.

  • strDescription
    Type: System.String

    The description for the list template.

  • bSaveData
    Type: System.Boolean

    true to save the data of the original list along with the list template; otherwise, false.

Exceptions

Exception Condition
Exception

Cannot save the list as a template.

Examples

The following code example saves a list, including its user data, on a specified site as a template.

This example requires using directives (Imports in Visual Basic) for the Microsoft.SharePoint and Microsoft.SharePoint.Utilities namespaces.

Dim siteCollection As SPSite = SPContext.Current.Site
Try
    Dim list As SPList = siteCollection.AllWebs("Site_Name").Lists("List_Title")
    list.SaveAsTemplate("File_Name.stp", "List_Template_Title", "Description", True)
Finally
    siteCollection.Dispose()
End Try
SPSite oSiteCollection = SPContext.Current.Site;
SPList oList = oSiteCollection.AllWebs["Site_Name"].Lists["List_Title"];
oList.SaveAsTemplate("File_Name.stp", "List_Template_Title", 
    "Description", true);

See Also

Reference

SPList Class

SPList Members

Microsoft.SharePoint Namespace