如何使用客户端对象模型关联SharePoint工作流?

时间:2011-02-15 18:18:31

标签: c# sharepoint-2010 sharepoint-workflow sharepoint-clientobject

使用SharePoint对象模型(SP 2010),如何将工作流与给定列表相关联?

我已经能够关联工作流程,但配置设置不会保存回SharePoint。换句话说,基本WorkflowAssociationCreationInformation将保存回SharePoint,但不会保存使用WorkflowAssociation的任何其他配置设置。

以下是我一直在研究的代码:

var context = new ClientContext( url );
Web site = context.Web;

var query = context.LoadQuery( site.WorkflowTemplates.Where( x => x.Name == "My Template Name" ) );
context.ExecuteQuery();
WorkflowTemplate wfTemplate = query.Single();

var wfc = new WorkflowAssociationCreationInformation();
wfc.HistoryList = site.Lists.GetByTitle( "Workflow History" );
wfc.Name = "My Workflow Name";
wfc.TaskList = site.Lists.GetByTitle( "Tasks" );
wfc.Template = wfTemplate;

List list = site.Lists.GetByTitle( "List Name" );

WorkflowAssociation wf = list.WorkflowAssociations.Add( wfc );
wf.AllowManual = false; // is never updated
wf.AutoStartChange = false; // is never updated
wf.AutoStartCreate = true; // is never updated
wf.Enabled = true; // is never updated
string assocData = GetAssociationXml(); // internal method
wf.AssociationData = assocData; // is never updated

context.Load( wf );
context.ExecuteQuery(); // does not update the SP workflow with any of the new wf settings

2 个答案:

答案 0 :(得分:1)

设置配置项后

list.WorkflowAssociations.Update(wf)将更新WorkflowAssociation上的配置项。

答案 1 :(得分:0)

    ...
    wf.AssociationData = assocData;
    wf.Update();//Update association config
    list.Update();//Update the list

    context.Load(wf);
    context.ExecuteQuery();