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
)
參數
web
Type: Microsoft.SharePoint.SPWeb若要匯出的網站。
solutionFilePath
Type: System.StringPath、 檔案名稱及將建立的方案檔案的副檔名。當方法執行空格會移除檔案名稱,會其他不合法的字元。如果指定路徑上已經存在具有相同名稱的方案檔案 (.wsp),它會被覆寫。
title
Type: System.String
description
Type: System.String說明的網站範本的詳細的資訊。這個參數中傳遞的值會做為元素資訊清單中,同時也用於的Onet.xml檔案的專案項目Description屬性值之WebTemplate元素Description屬性的值。
exportMode
Type: Microsoft.SharePoint.SPSolutionExporter.ExportMode指定要匯出的網站中有多少。如果您想要使用相同的網站集合內的網站範本為匯出的網站 ;,傳遞FullReuse否則,傳遞FullPortability。
includeContent
Type: System.Boolean若要在網站的網頁 ; 中包含的所有清單及文件庫內容的true否則false。
備註
您可以使用此方法來建立方案套件,您可以匯入Microsoft Visual Studio 2010進行進一步修改。如需詳細資訊,請參閱 <匯入現有的 SharePoint 網站中的項目。
此方法所建立的解決方案包含部分或所有功能,如下表中所列。如果網站不包含這些佈建的元素,則會省略功能。
![]() |
---|
匯入 SharePoint 方案套件的專案範本Visual Studio 2010變更方案檔案中的某些功能的組合。特別是,它會建立不同的元素資訊清單的每個內容類型而不是單一資訊清單中並保留所有內容型別定義。 |
功能 |
範圍 |
包含 |
---|---|---|
網站範本 |
Site |
|
清單執行個體 |
Web |
|
模組 |
Web |
|
屬性包 |
Web |
|
工作流程數 |
Web |
|
自訂動作 |
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
請參閱
參照
Microsoft.SharePoint namespace