SPWorkflowManager.StartWorkflow Method (Object, SPWorkflowAssociation, String, SPWorkflowRunOptions)
Creates and starts a new workflow instance on a specified object, based on a specified workflow association, with specified event parameters, and with specified options for running the workflow instance.
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: Yes
Available in SharePoint Online
public SPWorkflow StartWorkflow( Object context, SPWorkflowAssociation association, string eventData, SPWorkflowRunOptions runOptions )
Parameters
- context
- Type: System.Object
The object on which to run the workflow.
- association
- Type: Microsoft.SharePoint.Workflow.SPWorkflowAssociation
The workflow association on which to base the new workflow instance.
- eventData
- Type: System.String
A string that contains event parameters.
- runOptions
- Type: Microsoft.SharePoint.Workflow.SPWorkflowRunOptions
An enumeration value that specifies how the workflow instance should run.
If the argument is RunOptions.Synchronous, the method tries to start the workflow immediately; if it cannot be started immediately, then the method returns null.
If the argument is RunOptions.SynchronousAllowPostpone, the method tries to start the workflow immediately; if it cannot be started immediately, it is deferred and the method returns an SPWorkflow object referencing the unstarted workflow.
If the argument is RunOptions.Asynchronous, then the start of the workflow is deferred and the method returns an SPWorkflow object referencing the unstarted workflow.
Return Value
Type: Microsoft.SharePoint.Workflow.SPWorkflowThe new workflow instance or null, depending on the argument to the runOptions parameter.
| Exception | Condition |
|---|---|
| ArgumentNullException |
The argument to the item parameter or the association parameter is null. |
| ArgumentException |
The workflow association passed to the association parameter is not compatible with the list item passed to the item parameter. The item might have the wrong content type or belong to the wrong type of list. Or the content type of the item is derived from the WorkflowTask content type but the IsDeclarative property of the workflow association is false; only declarative workflows can be started on a task item. An ArgumentException is also thrown if the workflow association's Enabled property is false. |
| UnauthorizedAccessException |
The current user has insufficient permissions to start the workflow. |
| SPException |
The item is currently locked due to a short term lock or check-out. |
Pass in the current site to trigger a site workflow to start.
using (SPSite currentSite = new SPSite(SPContext.Current.Site.ID))
{
SPWorkflowAssociation assoc = currentSite.RootWeb.WorkflowAssociations.GetAssociationByName("Site Workflow Demo", System.Globalization.CultureInfo.InvariantCulture);
currentSite.WorkflowManager.StartWorkflow(currentSite, assoc, "", SPWorkflowRunOptions.SynchronousAllowPostpone);
}
- 5/19/2010
- Paul Turner