Export (0) Print
Expand All

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)

public static void ExportWeb(
	SPWeb web,
	string solutionFilePath,
	string title,
	string description,
	SPSolutionExporter.ExportMode exportMode,
	bool includeContent
)

Parameters

web
Type: Microsoft.SharePoint.SPWeb

The Web site to export.

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.

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.

NoteNote

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.

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("http://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();
        }
    }
}
Show:
© 2014 Microsoft