如何在Sharepoint 2010中终止工作流程

时间:2011-11-08 09:16:28

标签: visual-studio-2010 sharepoint sharepoint-2010

我在Sharepoint 2010中完成自定义工作流任务后,目前正面临此错误。它显示错误“发生错误”,我怀疑工作流未正确终止。如何以编程方式终止工作流程?我看到大多数网站要求我们使用下面的代码,但我不知道如何实现这些代码。

SPWorkflowCollection 
itemWorkflowCollection= listItem.Workflows;
foreach (SPWorkflow itemWorkflow in itemWorkflowCollection)
{
  //cycle workflows associated to the item (listItem)
  if (!itemWorkflow.IsCompleted && itemWorkflow.InternalState == SPWorkflowState.Running)
  {
    foreach (SPWorkflowTask taskWorkflow in itemWorkflow.Tasks)
    {
      //cycle throught all tasks associated to the workflow
      //if task is not completed
      if (taskWorkflow["PercentComplete"].ToString() != “1″)
      {
        //you can cancel or change the running tasks before canceling the workflow
        taskWorkflow["Status"] = “Canceled”;
        taskWorkflow["PercentComplete"] = 1;
        web.AllowUnsafeUpdates = true;
        taskWorkflow.Update();
      }
    }
    SPWorkflowManager.CancelWorkflow(itemWorkflow);
  }
}

0 个答案:

没有答案