2010-08-12 4 views
8

Nous utilisons SharePoint Foundation 2010.Ajouter un flux de travail SharePoint à une liste par programme

Nous avons créé un workflow qui vérifie l'état d'une liste de tâches.

Si nous associons le flux de travail à la liste dans l'interface utilisateur de SharePoint, cela fonctionne correctement. Nous nous demandions comment nous pourrions l'associer automatiquement, peut-être dans le code du récepteur de fonctions qui définit le site?

Répondre

10
// 1. create an instance of the SPWorkflowAssociation class 
SPWorkflowAssociation workflowAssociation = 
    SPWorkflowAssociation.CreateListAssociation(workflowTemplate, associationName, taskList, historyList); 

// 2. set start options 
workflowAssociation.AllowManual = true; 
workflowAssociation.AutoStartChange = false; 
workflowAssociation.AutoStartCreate = false; 

// 3. set additional association options (if any) 
workflowAssociation.AssociationData = associationData; 

// 4. add workflow association to the list 
list.WorkflowAssociations.Add(workflowAssociation); 

// 5. enable workflow association, so it is displayed in the user interface 
workflowAssociation.Enabled = true; 
Questions connexes