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.
If you are already playing with SharePoint 2010 and BCS, you would have noticed that there is no option to associate workflows for external lists. Many users have asked me whether these external list support workflows, so here is the answer from Tom Rizzo, SharePoint Senior Director, at the MSDN forums:
You can associate a workflow as a custom action for your External List in SPD. You probably (and I'll have to double check but I'm 99% sure) can't have a workflow fire by default against an external list since the workflow engine won't see things changing in the backend system.
Now, workflow is pluggable in 2010 so you might be able to plug in your own event provider into our workflow engine and watch the backend yourself. I haven't tried to do that yet so I don't know if it's feasible but it's something to take a look at if you want automatic workflow start but definitely clicking a button on the ribbon on an external list and triggering a workflow is supported.
Rather than creating an external list, you may want to instead create a SharePoint list with external columns so you get more SharePoint native features.
Hope this helps.
Tom
Today people use SharePoint Designer, Visual Studio (I haven’t played around creating workflows with VS though) or third party tools like K2, Nintex for building/designing workflows. Adding to this ‘elite list’ of workflow designers is Visio 2010!
Yep, now business users can make use of Visio 2010 to create workflows which can be exported. Though there is no information on whether these exported workflows can be imported using SharePoint Designer 2010 or directly from SharePoint 2010, I think SharePoint Designer 2010 should support importing these Visio SharePoint Workflows.
If you are in the Office 2010 technical preview, you can download Visio 2010.
Below are some screenshots of the new Visio 2010 SharePoint Workflow Template:


Here is my simple workflow I designed:

You can also validate your workflow before exporting or saving

After its successfully validated, you can then export

Exporting the workflow creates a .vwi file:

The .vwi is nothing but a but a zip file which consists of:

What happens next is yet to be figured and I hope information will start flowing as soon as Microsoft unveils SharePoint 2010 in the SharePoint Conference!
Until then, lets enjoy designing workflows in Visio 2010!