使用SharePoint 2010中的SP对象模型从列表中删除工作流

时间:2011-10-28 17:55:40

标签: sharepoint sharepoint-2010 sharepoint-workflow sharepoint-list sharepoint-object-model

我有兴趣使用SP对象模型从列表中删除工作流。我怎么能这样做?

我今天没有太多运气了!

2 个答案:

答案 0 :(得分:1)

行。所以这是我写的函数,从列表中删除工作流。希望它可以帮助某人:)


/// <summary>
/// Removes the workflow.
/// </summary>
/// <param name="workflowName">Name of the workflow.</param>
/// <param name="spList">The sp list.</param>
private static void RemoveWorkflow(string workflowName, SPList spList)
{
    SPWorkflowAssociation spWorkflowAssociation =
        spList.WorkflowAssociations.Cast<SPWorkflowAssociation>()
          .FirstOrDefault(workflowAssociation => workflowAssociation.Name.Equals(workflowName));

    if (spWorkflowAssociation != null)
    {
        spList.WorkflowAssociations.Remove(spWorkflowAssociation.Id);
    }

    spList.Update();
}

答案 1 :(得分:0)

试试这段代码,

   using(SPSite oSite = new SPSite("http://localhost/"))
   {
      using(SPWeb oWeb = oSite.OpenWeb())
      {
        SPList oList = oWeb.Lists["DocumentLib"];
        SPWorkflowAssociation objWorkflowAssociation = oList.WorkflowAssociations.Cast<SPWorkflowAssociation>().FirstOrDefault(workflowAssociation => workflowAssociation.Name.Equals("Approval Workflow"));
        if (objWorkflowAssociation != null)
        {
            oList.WorkflowAssociations.Remove(objWorkflowAssociation.Id);
        }
        oList.Update();
      }
   }

它的工作终结......