我有兴趣使用 SP 对象模型从列表中删除工作流。我怎样才能做到这一点?
我今天在 Google 上运气不佳!
我有兴趣使用 SP 对象模型从列表中删除工作流。我怎样才能做到这一点?
我今天在 Google 上运气不佳!
好的。所以这是我编写的从列表中删除工作流的函数。希望它可以帮助某人:)
/// <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();
}
试试这个代码,
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();
}
}
它对我有用...