共用方式為


SPSolutionExporter.ExportWeb method

會指定的網站匯出為方案檔案中的 Web 範本。

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

Syntax

'宣告
Public Shared Sub ExportWeb ( _
    web As SPWeb, _
    solutionFilePath As String, _
    title As String, _
    description As String, _
    exportMode As SPSolutionExporter.ExportMode, _
    includeContent As Boolean _
)
'用途
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
)

參數

  • solutionFilePath
    Type: System.String

    Path、 檔案名稱及將建立的方案檔案的副檔名。當方法執行空格會移除檔案名稱,會其他不合法的字元。如果指定路徑上已經存在具有相同名稱的方案檔案 (.wsp),它會被覆寫。

  • title
    Type: System.String

    網站範本的標題。這個參數中傳遞的值會做為專案檔案之元素的Onet.xmlTitle屬性的值。

  • description
    Type: System.String

    說明的網站範本的詳細的資訊。這個參數中傳遞的值會做為元素資訊清單中,同時也用於的Onet.xml檔案的專案項目Description屬性值之WebTemplate元素Description屬性的值。

  • includeContent
    Type: System.Boolean

    若要在網站的網頁 ; 中包含的所有清單及文件庫內容的true否則false。

備註

您可以使用此方法來建立方案套件,您可以匯入Microsoft Visual Studio 2010進行進一步修改。如需詳細資訊,請參閱 <匯入現有的 SharePoint 網站中的項目

此方法所建立的解決方案包含部分或所有功能,如下表中所列。如果網站不包含這些佈建的元素,則會省略功能。

注意事項注意事項

匯入 SharePoint 方案套件的專案範本Visual Studio 2010變更方案檔案中的某些功能的組合。特別是,它會建立不同的元素資訊清單的每個內容類型而不是單一資訊清單中並保留所有內容型別定義。

功能

範圍

包含

網站範本

Site

  • 元素資訊清單包含WebTemplate元素。

  • 包含網站組態Onet.xml檔案。

  • 網站的預設語言的語言資源檔案。檔案含有SPUserResource物件,例如會顯示文字的網站標題TitleResource從匯出的字串。

清單執行個體

Web

  • 每個清單或文件庫中的網站元素資訊清單。每一個資訊清單包含ListInstance元素定義之執行個體。

  • 每個清單或文件庫Schema.xml檔案。

  • 包含定義在清單和文件庫上使用的所有欄位的欄位元素單一元素資訊清單。

  • 包含定義在清單和文件庫上使用的所有內容類型的ContentType元素單一元素資訊清單。

  • 網站的預設語言的語言資源檔案。

模組

Web

  • 一或多個元素資訊清單與模組元素的佈建表單、 自訂頁面、 文件範本及其他網站所使用的檔案。

  • 網站的預設語言的語言資源檔案。

屬性包

Web

  • 單一項目資訊清單包含許多 PropertyBag 元素,以定義組態資料,以及其他保存在網站上使用的設定。

  • 網站的預設語言的語言資源檔案。

工作流程數

Web

  • 包含網站中的清單定義工作流程關聯的 WorkflowAssociation 元素元素資訊清單。

  • 網站的預設語言的語言資源檔案。

自訂動作

Web

包含定義 Web 範圍和範圍清單自訂動作的CustomAction元素元素資訊清單。

此外,方案資訊清單定義在任何其他網站會在啟動使用者解決方案時啟動相依性。如果啟動相依性存在,請啟動 Web 範本解決方案之前,必須先啟動這些解決方案。

Examples

下列範例會為主控台應用程式,取得網站的參照,並將它儲存為網頁範本方案,建立新的解決方案檔案的應用程式目錄中。應用程式然後取得檔案的參照,並列印主控台它的相關資訊。

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

請參閱

參照

SPSolutionExporter class

SPSolutionExporter members

Microsoft.SharePoint namespace

其他資源

Site Types: WebTemplates and Site Definitions

Web Templates