Terminating workflows
You can use a few service operations in the Workflow web service to terminate instances of site, reusable, and list workflows, depending on the workflow type and the identifiers available to you.
Terminating site workflows
You can use one of the following service operations to terminate a running site workflow instance:
-
If you have the identifier of the site workflow instance to terminate, you can use this operation to terminate the specified workflow instance.
-
If you do not have the identifier of the site workflow instance to terminate, you can use this operation to terminate either just the current instance of the specified site workflow, or both the current instance and all previous instances of the specified site workflow.
Terminating reusable and list workflows
You can use one of the following service operations to terminate a running site workflow instance:
-
If you have the identifier of the reusable or list workflow instance to terminate, you can use this operation to terminate the specified workflow instance for a list item in a SharePoint list.
-
You can use this operation to terminate either just the current instance of the specified reusable or list workflow, or both the current instance and all previous instances of the specified reusable or list workflow, for a file in a SharePoint document library.
-
TerminateWorkflowByNameForListItem
If you do not have the identifier of the reusable or list workflow instance to terminate, you can use this operation to terminate either just the current instance of the specified reusable or list workflow, or both the current instance and all previous instances of the specified reusable or list workflow, for a list item in a SharePoint list.
Example
The following code example uses the TerminateWorkflowByName service operation to terminate the latest running instance of the specified workflow for the current site.
public bool TerminateWorkflowForSite(string workflowName) { try { // Use the TerminateWorkflowByName service operation to terminate // the latest running instance of the specified site workflow // for the current site. soapClient.TerminateWorkflowByName( "", workflowName, false); // If no error was received, the workflow was successfully // terminated. If so, return true. return true; } catch { // An error occurred while trying to start the site workflow. return false; } }