2. June 2010 21:57
by Chaks
0 Comments
So you have created a very cool site workflow in SharePoint Designer 2010, published and you want to start programmatically.
Below is the code snippet to start a site workflow. Credit goes to MSDN user Paul Turner :
static void Main(string[] args)
{
using (SPSite spSite = new SPSite("http://mysite"))
{
using (SPWeb spWeb = spSite.RootWeb)
{
SPWorkflowAssociation workflowAssociation
= spWeb
.WorkflowAssociations
.GetAssociationByName("MySiteWorkflow",
CultureInfo.InvariantCulture);
if (workflowAssociation != null)
{
SPWorkflow siteWorkflow
= spSite
.WorkflowManager
.StartWorkflow(spSite,
workflowAssociation,
"<Data><SalesOrderId>71774</SalesOrderId></Data>",
SPWorkflowRunOptions.Asynchronous);
}
}
}
Console.WriteLine("Workflow Started");
Console.Read();
}
The <Data><SalesOrderId>71774</SalesOrderId></Data> is the initiation form data. Replace SalesOrderId with yours.