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

发布于 2024-12-12 08:06:57 字数 60 浏览 1 评论 0原文

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

我今天在谷歌上运气不太好!

I am interested in removing a Workflow from the list using the SP Object Model. How can I do this?

I am not having much luck with Google today!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦里梦着梦中梦 2024-12-19 08:06:57

好的。这是我编写的从列表中删除工作流程的函数。希望它对某人有帮助:)


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

OK. So here is the function I wrote that removes the Workflow from the list. Hope it helps someone :)


/// <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();
}
我一直都在从未离去 2024-12-19 08:06:57

试试这个代码,

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

它对我有效......

Try this code,

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

Its working on my end...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文