0

我有興趣使用SP對象模型從列表中刪除工作流。我怎樣才能做到這一點?使用SharePoint 2010中的SP對象模型從列表中刪除工作流

今天我對Google沒有太大的運氣!

+0

那麼,你可以從HTTP反向工作://獲取-spscripts.com/2010/08/add-workflow-to-sharepoint-list-in-all.html有趣的API短語是[SPList.WorkflowAssociations](http://msdn.microsoft.com/en-us/library /microsoft.sharepoint.splist.workflowassociations.aspx):-) – 2011-10-28 17:58:44

回答

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(); 
} 
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(); 
     } 
    } 

它的工作在我結束...

+0

這將刪除工作流關聯(但不限於),但工作流程仍會在工作流程設置中顯示爲非活動工作流程。你將如何徹底從網站中刪除? – MrMVCMan

相關問題