Share via


Workflow Object Model in Windows SharePoint Services Overview

This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

After you deploy your workflow solution, you can use the Windows SharePoint Services 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.Windows.SharePoint.Workflow Objects

The Microsoft.SharePoint.Workflow namespace represents the workflow functionality contained in Windows SharePoint Services.

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.

Use the RemoveWorkflowAssociation method to remove a workflow association from a list, and the RemoveWorkflowAssociation method to remove a workflow association from a site or list content type.

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 given 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.

Use the Workflows property to return an SPWorkflowCollection object that represents the workflows currently running for that list item.

Managing Running Workflow Instances Programmatically

Users interact with the workflows running on items individually, through the Windows SharePoint Services user interface. But Windows SharePoint Services 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 theStartWorkflow(SPListItem, SPWorkflowAssociation, String) or StartWorkflow(SPListItem, SPWorkflowAssociation, String, Boolean) method.

See Also

Concepts

Workflow Development for Windows SharePoint Services