共用方式為


SPSolutionExporter.ExportWorkflowToList method

將指定的工作流程範本匯出為方案的文件庫。

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

Syntax

'宣告
Public Shared Function ExportWorkflowToList ( _
    web As SPWeb, _
    solutionFileName As String, _
    title As String, _
    description As String, _
    workflowTemplateName As String, _
    destinationListUrl As String _
) As String
'用途
Dim web As SPWeb
Dim solutionFileName As String
Dim title As String
Dim description As String
Dim workflowTemplateName As String
Dim destinationListUrl As String
Dim returnValue As String

returnValue = SPSolutionExporter.ExportWorkflowToList(web, _
    solutionFileName, title, description, _
    workflowTemplateName, destinationListUrl)
public static string ExportWorkflowToList(
    SPWeb web,
    string solutionFileName,
    string title,
    string description,
    string workflowTemplateName,
    string destinationListUrl
)

參數

  • solutionFileName
    Type: System.String

    會建立解決方案檔的名稱。

  • description
    Type: System.String

    說明解決方案的詳細的資訊。

  • workflowTemplateName
    Type: System.String

    若要匯出的工作流程範本的名稱。

  • destinationListUrl
    Type: System.String

    在此方案檔案必須要建立的文件庫伺服器相對 URL。

傳回值

Type: System.String
新的解決方案檔案的 URL。如果無法建立解決方案,則會傳回空字串。

備註

這個方法就會嘗試將新的方案檔案匯出至指定的目的地使用指定的檔案名稱。如果具有此名稱的檔案已存在,然後一系列的"檔案名稱-2.wsp""FileName 3.wsp"嘗試進行的尋找的唯一檔案名稱。如果到達"FileName 1000.wsp"且具有該名稱的檔案已經存在,此方法會擲回InvalidOperationException例外狀況。

Examples

下列範例會將工作流程範本匯出至 [網站資產] 清單的主控台應用程式。範例程式碼中使用的工作流程範本為 「 工作流程 」。執行程式碼之前,您應在網站上替代存在的工作流程範本的名稱。

using System;
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 solutionFileName = "Task Workflow.wsp";
                    string title = "Task Workflow";
                    string description = "This solution was created programmatically.";
                    string templateName = "Task Workflow";
                    string solutionFileUrl = string.Empty;

                    // Get the Site Assets list.
                    SPList catalog = site.GetCatalog(SPListTemplateType.DocumentLibrary);
                    string destinationListUrl = catalog.RootFolder.ServerRelativeUrl;

                    try
                    {
                        // Export the template to a list.
                        solutionFileUrl = SPSolutionExporter.ExportWorkflowToList(
                            web,
                            solutionFileName,
                            title,
                            description,
                            templateName,
                            destinationListUrl);
                    }
                    catch (SPException ex)
                    {
                        Console.WriteLine(ex.Message);
                    }

                    // Get a reference to the solution package.
                    if (String.IsNullOrEmpty(solutionFileUrl))
                    {
                        Console.WriteLine("A solution was not created.");
                    }
                    else
                    {
                        // Get the solution file.
                        SPFile solutionFile = web.GetFile(solutionFileUrl);

                        // Print information about the solution file.
                        Console.WriteLine("Name: {0}", solutionFile.Name);
                        Console.WriteLine("Size: {0:n0} bytes", solutionFile.Length);
                    }
                }
            }
            Console.Write("\nPress ENTER to continue....");
            Console.ReadLine();
        }
    }
}
Imports System
Imports Microsoft.SharePoint

Module ConsoleApp

    Sub Main()

        Using site As New SPSite("https://localhost")
            Using web As SPWeb = site.RootWeb

                Dim solutionFileName As String = "Task Workflow.wsp"
                Dim title As String = "Task Workflow"
                Dim description As String = "This solution was created programmatically."
                Dim templateName As String = "Task Workflow"
                Dim solutionFileUrl As String = String.Empty

                ' Get the Site Assets list.
                Dim catalog As SPList = site.GetCatalog(SPListTemplateType.DocumentLibrary)
                Dim destinationListUrl As String = catalog.RootFolder.ServerRelativeUrl

                Try
                    ' Export the template to a list.
                    solutionFileUrl = SPSolutionExporter.ExportWorkflowToList( _
                        web, _
                        solutionFileName, _
                        title, _
                        description, _
                        templateName, _
                        destinationListUrl)
                Catch ex As SPException
                    Console.WriteLine(ex.Message)
                End Try

                ' Get a reference to the solution package.
                If String.IsNullOrEmpty(solutionFileUrl) Then
                    Console.WriteLine("A solution was not created.")
                Else
                    ' Get the solution file.
                    Dim solutionFile As SPFile = web.GetFile(solutionFileUrl)

                    ' Print information about the solution file.
                    Console.WriteLine("Name: {0}", solutionFile.Name)
                    Console.WriteLine("Size: {0:n0} bytes", solutionFile.Length)
                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