Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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

share|improve this question

2 Answers 2

up vote 1 down vote accepted

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.

share|improve this answer
    
Thank you, it worked. –  Baptiste Wicht Oct 27 '11 at 13:52
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 !

share|improve this answer
    
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

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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