SPSolutionExporter.ExportWebToGallery method (SPWeb, String, String, String, SPSolutionExporter.ExportMode, Boolean)
會指定的網站匯出為解決方案庫中的 Web 範本。
Namespace: Microsoft.SharePoint
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Syntax
'宣告
Public Shared Function ExportWebToGallery ( _
web As SPWeb, _
solutionFileName As String, _
title As String, _
description As String, _
exportMode As SPSolutionExporter.ExportMode, _
includeContent As Boolean _
) As String
'用途
Dim web As SPWeb
Dim solutionFileName As String
Dim title As String
Dim description As String
Dim exportMode As SPSolutionExporter.ExportMode
Dim includeContent As Boolean
Dim returnValue As String
returnValue = SPSolutionExporter.ExportWebToGallery(web, _
solutionFileName, title, description, _
exportMode, includeContent)
public static string ExportWebToGallery(
SPWeb web,
string solutionFileName,
string title,
string description,
SPSolutionExporter.ExportMode exportMode,
bool includeContent
)
參數
web
Type: Microsoft.SharePoint.SPWeb若要匯出的網站。
solutionFileName
Type: System.String解決方案檔 (.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。
傳回值
Type: System.String
包含解決方案庫中的新解決方案檔案的 URL 的字串。如果無法建立解決方案,則會傳回空字串。
備註
此方法會嘗試將新的方案檔案複製至解決方案庫使用指定的檔案名稱。如果具有此名稱的檔案已存在,然後一系列的"檔案名稱-2.wsp""FileName 3.wsp"嘗試進行的尋找的唯一檔案名稱。如果到達"FileName 1000.wsp",並在圖庫中已經存在具有該名稱的檔案,則方法會擲回InvalidOperationException例外狀況。
這個方法所建立的解決方案包含一些或所有功能,如下表中所列。如果網站不包含這些佈建的元素,則會省略功能。
功能 |
範圍 |
包含 |
---|---|---|
網站範本 |
Site |
|
清單執行個體 |
Web |
|
模組 |
Web |
|
屬性包 |
Web |
|
工作流程數 |
Web |
|
自訂動作 |
Web |
包含定義 Web 範圍和範圍清單自訂動作的CustomAction元素元素資訊清單。 |
Examples
下列範例會為主控台應用程式,取得網站的參照,並呼叫ExportWebToGallery方法,以儲存為解決方案庫中的 Web 範本解決方案的網站。匯出解決方案後, 之應用程式呼叫GetAvailableWebTemplates方法,以擷取新的範本,並列印主控台其標題。
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.OpenWeb("Child"))
{
string solutionFileName = "Test Site.wsp"; // If this name exists, a number is appended.
string templateTitle = String.Format("{0} Web Template", web.Title);
string templateDesc = "This template was saved programmatically.";
// Save the web as a solution in the Solutions Gallery.
string solutionFileUrl = SPSolutionExporter.ExportWebToGallery(
web,
solutionFileName,
templateTitle,
templateDesc,
SPSolutionExporter.ExportMode.FullReuse,
false // Do not include content.
);
if (!String.IsNullOrEmpty(solutionFileUrl))
{
// The solution file name might have changed, so get it from the Url.
string newFileName = Path.GetFileNameWithoutExtension(solutionFileUrl);
// Get the Web template.
SPWebTemplate template = web
.GetAvailableWebTemplates(web.Language)
.Cast<SPWebTemplate>()
.FirstOrDefault(t => t.Title == newFileName);
if (template != null)
{
// Print information about the Web template.
Console.WriteLine("Template Title: {0}", template.Title);
}
}
}
}
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.OpenWeb("Child")
' If this name exists, a number is appended.
Dim solutionFileName As String = "Test Site.wsp"
Dim templateTitle As String = String.Format("{0} Web Template", web.Title)
Dim templateDesc As String = "This template was saved programmatically."
' Save the web as a solution in the Solutions Gallery.
Dim solutionFileUrl As String = SPSolutionExporter.ExportWebToGallery(web, _
solutionFileName, _
templateTitle, _
templateDesc, _
SPSolutionExporter.ExportMode.FullReuse, _
False)
If Not String.IsNullOrEmpty(solutionFileUrl) Then
' The solution file name might have changed, so get it from the Url.
Dim newFileName As String = Path.GetFileNameWithoutExtension(solutionFileUrl)
' Get the Web template.
Dim template As SPWebTemplate = _
web.GetAvailableWebTemplates(web.Language).Cast(Of SPWebTemplate)().FirstOrDefault(Function(t) t.Title = newFileName)
If template IsNot Nothing Then
' Print information about the Web template.
Console.WriteLine("Template Title: {0}", template.Title)
End If
End If
End Using
End Using
Console.Write(vbCrLf & "Press ENTER to continue....")
Console.Read()
End Sub
End Module
請參閱
參照
Microsoft.SharePoint namespace