Home > development, error, event handlers, MOSS, MS SharePoint Sever, sharepoint, sps > Start a Workflow Programmatically

Start a Workflow Programmatically

There could be many ways to start a workflow programmatically, here is one of them:

You will need to specify the workflow name.


private static void StartWorkflow(SPListItem listItem, string workflowName)
{
            SPWorkflowAssociation wfAssoc = listItem.ParentList.WorkflowAssociations.GetAssociationByName(workflowName, System.Globalization.CultureInfo.CurrentCulture);

            listItem.Web.Site.WorkflowManager.StartWorkflow(listItem, wfAssoc, wfAssoc.AssociationData, true);

            listItem.Update();
}

Call the above function like this:

StartWorkflow(listItem, myWorkflowName);

Hope this helps–
Rehman.

Advertisements
  1. Stephan Onisick
    December 19, 2011 at 2:58 pm

    Question: Why do you have to update the list item.

    thanks,
    Stephan Onisick

  2. July 11, 2013 at 6:41 pm

    Thanks so much. Works beautifully!

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: