SPSolutionExporter.ExportWorkflowToList Method
Exports the specified workflow template as a solution in a document library.
Namespace: Microsoft.SharePoint
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: No
Syntax
'Declaration
Public Shared Function ExportWorkflowToList ( _
web As SPWeb, _
solutionFileName As String, _
title As String, _
description As String, _
workflowTemplateName As String, _
destinationListUrl As String _
) As String
'Usage
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
)
Parameters
web
Type: Microsoft.SharePoint.SPWebThe Web site that contains the workflow template.
solutionFileName
Type: System.StringThe name of the solution file that will be created.
title
Type: System.StringThe title of the solution.
description
Type: System.StringDetailed information that describes the solution.
workflowTemplateName
Type: System.StringThe name of the workflow template to export.
destinationListUrl
Type: System.StringThe server-relative URL of the document library in which the solution file needs to be created.
Return Value
Type: System.String
The URL of the new solution file. If a solution could not be created, an empty string is returned.
Remarks
This method attempts to export the new solution file to the specified destination using the specified file name. If a file with this name already exists, then a series of "FileName-2.wsp", "FileName-3.wsp" attempts are made in an effort to find a unique file name. If "FileName-1000.wsp" is reached and a file with that name already exists, the method throws an InvalidOperationException exception.
Examples
The following example is a console application that exports a workflow template to the Site Assets list. 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.
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