Workflow Object Model Overview in SharePoint Foundation
Applies to: SharePoint Foundation 2010
After you deploy your workflow solution, you can use the Microsoft SharePoint Foundation object model to query workflow processes and programmatically perform workflow actions, such as adding a workflow to a list or starting a workflow for an item.
Major Microsoft.SharePoint.Workflow Objects
The Microsoft.SharePoint.Workflow namespace represents the workflow functionality contained in SharePoint Foundation.
The SPWorkflowTemplateCollection object represents the workflow templates currently deployed on a site. Each SPWorkflowTemplate object represents a workflow template and contains properties you can use to get or set information about the template, such as the instantiation data and the history and task lists for the template.
To associate a workflow to a list or document library, use the AddWorkflowAssociation method of the SPList object. To associate a workflow with a content type, use the AddWorkflowAssociation method of the SPContentType object. Both of these methods take an SPWorkflowAssociation object and add it to the specified list or content type, respectively. To create the appropriate workflow association, use the CreateListAssociation, CreateListContentTypeAssociation, or CreateSiteContentTypeAssociation method of the SPWorkflowAssociation object itself.
As with adding a workflow through the user interface, associating a workflow programmatically adds a status column for the workflow to the list.
Each SPWorkflowAssociation object represents a workflow template that is associated with a specific list or content type, and that contains properties that return custom information about that workflow's association with the specific list or content type. This information includes whether the workflow is enabled, whether the workflow can be started automatically, and the list or content type with which the workflow has been associated.
The SPWorkflowCollection represents the workflow instances that have run or are currently running on a specified list item. Each SPWorkflow object contains properties that return information about the workflow instance, such as whether the workflow has completed, its internal state, and its workflow history list. In addition, each workflow contains a collection of the tasks for the workflow, SPWorkflowTaskCollection.
Managing Running Workflow Instances Programmatically
Users interact with the workflows running on items individually, through the SharePoint Foundation user interface. But SharePoint Foundation provides functionality for you to centrally control the running instances of workflows across your site collection through the object model. Use the SPWorkflowManager object to manage the running instances of workflows across a site collection. The SPWorkflowManager object has no equivalent in the user interface. Use the SPWorkflowManager object to:
Start, run, or cancel workflows.
Return all the workflows currently running on a specific item.
Perform other workflow administration operations.
To manually start a specific workflow for an item—that is, a workflow that is not configured to start automatically—use the StartWorkflow(SPListItem, SPWorkflowAssociation, String) or StartWorkflow(SPListItem, SPWorkflowAssociation, String, Boolean) method.