我有一个与内容类型关联的工作流程。我尝试从相同内容类型的事件接收器中的代码启动它,因此当更新项目时,如果存在特定条件(状态 = 准备好审查),我将启动它。
//这一行确实找到了工作流关联
var assoc = properties.Web.ContentTypes["Experiment Document Set"]
.WorkflowAssociations.GetAssociationByName("Experiment Review Workflow",
ultureInfo.CurrentUICulture);
//我曾尝试使用我在网上找到的东西中的这一行,但它会返回 null
assoc = properties.Web.WorkflowAssociations
.GetAssociationByName("Experiment Review Workflow",
CultureInfo.CurrentUICulture);
下一行报错:
var result = properties.Web.Site.WorkflowManager
.StartWorkflow(properties.ListItem, assoc,string.Empty,
SPWorkflowRunOptions.Synchronous);
System.ArgumentException: Workflow failed to start because the workflow is associated with a content type that does not exist in a list. Before re-starting the workflow, the content type must be added to the list.
为了检查这一点,我查看了正在更新的列表项的内容类型,它是正确的
properties.ListItem.ContentType.Name "Experiment Document Set"
所以基本上我有一个与内容类型“实验文档集”关联的工作流。当我尝试从“实验文档集”中的事件接收器启动工作流时,我收到一条错误消息,指出列表中不存在内容类型“实验文档集”,这没有意义。
最佳答案
确保 assoc.Enabled = true。
关于c# - Sharepoint 2010 以编程方式启动工作流错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4565332/