2

I created a Sharepoint 2010 Sequential Workflow in a Visual Studio 2010 project. But I didn't found a way to associate it to one of my list. Every time I deploy to the site, I have to manually associate it with the good list.

The list is also created in the VS 2010 project.

Is there a way to associate my workflow to a list to be invoked every time an item is created or updated ?

Thanks

3

If you would like to associate workflow with the specific list when you deploy you solution by VS2010, you can select workflow, choose element property ans set Target List.

0
SPWorkflowTemplate baseTemplate =                                        currentSite.RootWeb.WorkflowTemplates.GetTemplateByName
                                                ("workflow", CultureInfo.InvariantCulture);
                                        SPWorkflowAssociation workflowAssociation =
                                            SPWorkflowAssociation.CreateListContentTypeAssociation(
                                                baseTemplate,
                                                "description",
                                                currentWeb.Lists["Tasks"],
                                                currentWeb.Lists["History"]);
                                        workflowAssociation.AllowManual = true;
                                        workflowAssociation.AutoStartChange = false;
                                        workflowAssociation.AutoStartCreate = false;
                                        siteContentType.WorkflowAssociations.Add(
                                            workflowAssociation);
                                        liste = currentWeb.Lists;
                                        foreach (SPList list in liste)
                                        {
                                            if (list.ContentTypes[0].Name == "ct")
                                            {
                                                list.WorkflowAssociations.
                                                    UpdateAssociationsToLatestVersion();
                                            }
                                        }

For adding to a specific content type. For lists should be the same. Good luck !

  • Thank you, but where do I have to put this code if it has to be executed on the deploy of a feature ? – Baptiste Wicht Oct 27 '11 at 13:28
  • In a feature activated could be placed – user3145 Oct 27 '11 at 13:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.