共用方式為


SPSolutionExporter.ExportWorkFlowTemplate method

將指定的工作流程範本匯出成方案檔案。

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

Syntax

'宣告
Public Shared Sub ExportWorkFlowTemplate ( _
    web As SPWeb, _
    solutionFilePath As String, _
    title As String, _
    description As String, _
    workflowTemplateName As String _
)
'用途
Dim web As SPWeb
Dim solutionFilePath As String
Dim title As String
Dim description As String
Dim workflowTemplateName As StringSPSolutionExporter.ExportWorkFlowTemplate(web, _
    solutionFilePath, title, description, _
    workflowTemplateName)
public static void ExportWorkFlowTemplate(
    SPWeb web,
    string solutionFilePath,
    string title,
    string description,
    string workflowTemplateName
)

參數

  • solutionFilePath
    Type: System.String

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

  • description
    Type: System.String

    說明範本的詳細的資訊。

  • workflowTemplateName
    Type: System.String

    若要匯出的工作流程範本的名稱。範本必須存在於網站上。

Examples

下面範例會將工作流程範本匯出成方案檔案的應用程式目錄中的主控台應用程式。範例程式碼中使用的工作流程範本為 「 工作流程 」。執行程式碼之前,您應在網站上替代存在的工作流程範本的名稱。

注意事項注意事項

建立工作流程範本的Microsoft SharePoint Designer 2010相關資訊,請參閱 「 建立 SharePoint Designer 可重複使用工作流程 」,在逐步解說: 匯入 Visual Studio 的 SharePoint Designer 可重複使用工作流程

using System;
using System.IO;
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 = "TaskWorkflow.wsp";
                    string solutionPath = AppDomain.CurrentDomain.BaseDirectory;
                    string solutionFilePath = SPSolutionExporter.PathCombine(solutionPath, solutionFile);

                    string solutionTitle = "Task";
                    string solutionDesc = "This template was saved programmatically.";
                    string templateName = "Task Workflow";

                    try
                    {
                        // Save the workflow in a solution file.
                        SPSolutionExporter.ExportWorkFlowTemplate(
                            web,
                            solutionFilePath,
                            solutionTitle,
                            solutionDesc,
                            templateName);
                    }
                    catch (SPException spx)
                    {
                        Console.WriteLine(spx.Message);
                    }


                    // 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 = "TaskWorkflow.wsp"
                Dim solutionPath As String = AppDomain.CurrentDomain.BaseDirectory
                Dim solutionFilePath As String = SPSolutionExporter.PathCombine(solutionPath, solutionFile)

                Dim solutionTitle As String = "Task"
                Dim solutionDesc As String = "This template was saved programmatically."
                Dim templateName As String = "Task Workflow"

                Try
                    ' Save the workflow in a solution file.
                    SPSolutionExporter.ExportWorkFlowTemplate(web, solutionFilePath, solutionTitle, solutionDesc, templateName)
                Catch spx As SPException
                    Console.WriteLine(spx.Message)
                End Try

                ' Print information about the file.
                Dim solutionFileInfo As 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