SPSolutionExporter.ExportWorkFlowTemplate Method

Exports the specified workflow template as a solution file.

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: No

Syntax

'Declaration
Public Shared Sub ExportWorkFlowTemplate ( _
    web As SPWeb, _
    solutionFilePath As String, _
    title As String, _
    description As String, _
    workflowTemplateName As String _
)
'Usage
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
)

Parameters

  • solutionFilePath
    Type: System.String

    The path, file name, and extension of the solution file that will be created. When the method executes, spaces are removed from the file name, as are other illegal characters. If a solution file (.wsp) with the same name already exists on the specified path, it is overwritten.

  • description
    Type: System.String

    Detailed information that describes the template.

  • workflowTemplateName
    Type: System.String

    The name of the workflow template to export. The template must exist on the Web site.

Examples

The following example is a console application that exports a workflow template as a solution file in the application directory. The workflow template used in the example code is "Task Workflow". You should substitute the name of a workflow template that exists on your site before running the code.

Note

For information about creating a workflow template in Microsoft SharePoint Designer 2010, see "Create a SharePoint Designer Reusable Workflow" in Walkthrough: Import a SharePoint Designer Reusable Workflow into Visual Studio.

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

See Also

Reference

SPSolutionExporter Class

SPSolutionExporter Members

Microsoft.SharePoint Namespace

Other Resources

Site Types: WebTemplates and Site Definitions