다음을 통해 공유


SPSolutionExporter.ExportWeb Method

Exports the specified Web site as a Web template in a solution file.

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

Syntax

'Declaration
Public Shared Sub ExportWeb ( _
    web As SPWeb, _
    solutionFilePath As String, _
    title As String, _
    description As String, _
    exportMode As SPSolutionExporter.ExportMode, _
    includeContent As Boolean _
)
'Usage
Dim web As SPWeb
Dim solutionFilePath As String
Dim title As String
Dim description As String
Dim exportMode As SPSolutionExporter.ExportMode
Dim includeContent As BooleanSPSolutionExporter.ExportWeb(web, solutionFilePath, _
    title, description, exportMode, includeContent)
public static void ExportWeb(
    SPWeb web,
    string solutionFilePath,
    string title,
    string description,
    SPSolutionExporter.ExportMode exportMode,
    bool includeContent
)

Parameters

  • solutionFilePath
    Type: System.String

    The path, file name, and extension of the solution file that will be created. When the method executes, spaces are removed from the file name, as are other illegal characters. If a solution file (.wsp) with the same name already exists on the specified path, it is overwritten.

  • title
    Type: System.String

    The title of the Web template. The value passed in this parameter is used as the value of the Title attribute in the Project element of an Onet.xml file.

  • description
    Type: System.String

    Detailed information that describes the Web template. The value passed in this parameter is used as the value of the Description attribute in the WebTemplate element in an element manifest and also for the value of the Description attribute in the Project element of an Onet.xml file.

  • exportMode
    Type: Microsoft.SharePoint.SPSolutionExporter.ExportMode

    Specifies how much of the Web site to export. Pass FullReuse if you intend to use the Web template within the same site collection as the exported Web site; otherwise, pass FullPortability.

  • includeContent
    Type: System.Boolean

    true to include the contents of all lists and document libraries in the Web site; otherwise false.

Remarks

You can use this method to create a solution package that you can import into Microsoft Visual Studio 2010 for further modification. For more information, see Importing Items from an Existing SharePoint Site.

The solution that is created by this method contains some or all of the Features listed in the following table. Features are omitted if the Web site does not contain the elements that they provision.

Note

The Import SharePoint Solution Package project template in Visual Studio 2010 changes the composition of some Features in the solution file. In particular, it creates a separate element manifest for each content type rather than keeping all content type definitions in a single manifest.

Feature

Scope

Includes

Web Template

Site

  • An element manifest that contains a WebTemplate element.

  • An Onet.xml file that contains the Web site configuration.

  • A language resource file for the default language of the Web site. The file contains strings exported from SPUserResource objects such as the TitleResource that backs the display text for the title of the Web site.

List Instances

Web

  • One element manifest for each list or document library in the Web site. Each manifest contains a ListInstance element that defines the instance.

  • A Schema.xml file for each list or library.

  • A single element manifest that contains Field elements that define all fields used on lists and libraries.

  • A single element manifest that contains ContentType elements that define all content types used on lists and libraries.

  • A language resource file for the default language of the Web site.

Modules

Web

  • One or more element manifests with a Module element that provisions forms, custom pages, document templates, and other files used by the Web site.

  • A language resource file for the default language of the Web site.

Property Bag

Web

  • A single element manifest that contains a number of PropertyBag elements that define configuration data and other persisted settings used on the Web site.

  • A language resource file for the default language of the Web site.

Workflows

Web

  • An element manifest that contains WorkflowAssociation elements that define workflow associations on lists in the Web site.

  • A language resource file for the default language of the Web site.

Custom Actions

Web

An element manifest that contains CustomAction elements that define Web-scoped and list-scoped custom actions.

In addition, the solution manifest defines an activation dependency upon any other user solution that is activated for the Web site. If activation dependencies exist, those solutions must be activated before the Web template solution is activated.

Examples

The following example is a console application that gets a reference to a Web site and saves it as a Web template solution, creating the new solution file in the application directory. The application then gets a reference to the file and prints information about it to the console.

using System;
using System.IO;
using System.Linq;
using Microsoft.SharePoint;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            using (SPSite site = new SPSite("https://localhost"))
            {
                using (SPWeb web = site.RootWeb)
                {
                    string solutionFile = "TestSite.wsp";
                    string solutionPath = AppDomain.CurrentDomain.BaseDirectory;
                    string solutionFilePath = SPSolutionExporter.PathCombine(solutionPath, solutionFile);

                    string templateTitle = "Test Template";
                    string templateDesc = "This template was saved programmatically.";

                    // Save the web as a template in a solution file.
                    SPSolutionExporter.ExportWeb(
                        web,
                        solutionFilePath,
                        templateTitle,
                        templateDesc,
                        SPSolutionExporter.ExportMode.FullPortability, // Include features that the site depends upon.
                        false // Do not include content.
                     );
 
                    // Print information about the file.
                    FileInfo solutionFileInfo = new FileInfo(solutionFilePath);
                    if (solutionFileInfo.Exists)
                    {
                        Console.WriteLine("File name: {0}", solutionFileInfo.Name);
                        Console.WriteLine("File size: {0:n0} KB", solutionFileInfo.Length / 1024);
                    }
                }
            }
            Console.Write("\nPress ENTER to continue....");
            Console.ReadLine();
        }
    }
}
Imports System
Imports System.IO
Imports Microsoft.SharePoint

Module ConsoleApp

    Sub Main()

        Using site As New SPSite("https://localhost")
            Using web As SPWeb = site.RootWeb

                Dim solutionFile As String = "TestSite.wsp"
                Dim solutionPath As String = AppDomain.CurrentDomain.BaseDirectory
                Dim solutionFilePath As String = SPSolutionExporter.PathCombine(solutionPath, solutionFile)

                Dim templateTitle As String = "Test Template"
                Dim templateDesc As String = "This template was saved programmatically."

                ' Save the web as a template in a solution file.
                ' Include features that the site depends upon.
                ' Do not include content.
                SPSolutionExporter.ExportWeb(web, solutionFilePath, _
                                             templateTitle, templateDesc, _
                                             SPSolutionExporter.ExportMode.FullPortability, _
                                             False)

                ' Print information about the file.
                Dim solutionFileInfo As FileInfo = New FileInfo(solutionFilePath)
                If solutionFileInfo.Exists Then
                    Console.WriteLine("File name: {0}", solutionFileInfo.Name)
                    Console.WriteLine("File size: {0:n0} KB", solutionFileInfo.Length / 1024)
                End If

            End Using
        End Using

        Console.Write(vbCrLf & "Press ENTER to continue....")
        Console.Read()
    End Sub

End Module

See Also

Reference

SPSolutionExporter Class

SPSolutionExporter Members

Microsoft.SharePoint Namespace

Other Resources

Site Types: WebTemplates and Site Definitions

Web Templates