Wednesday, 1 August 2012

"Programmatically Workflow association through C# coding Technique."

step1:
Select Console Application Template from New project in visual Studio 2010 and select .net framework 3.5 also then
AddRefrence ==> Microsoft.Sharepoint.dll


Step2;

Associationworkflow.cs

Add to namespace:
using Microsoft.SharePoint;
using Microsoft.SharePoint.Workflow;



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Workflow;

namespace ConsoleApplication1
{
    class Program

    {
        static void Main(string[] args)
        {
            //Get the site, web and list.

            SPSite site = new SPSite(@"http://sp2010:2173");
            SPWeb web = site.AllWebs["vswf"];
            SPList list = web.Lists["Links"];

            // Get the Simlpeworkflow template.
            SPWorkflowTemplate simpleworkflow =
                web.WorkflowTemplates.GetTemplateByName("SimpleWorkflow",
                System.Globalization.CultureInfo.CurrentCulture);

            // create the association
            SPWorkflowAssociation assoc =
                SPWorkflowAssociation.CreateListAssociation(
                SimpleWorkflow, "SimpleWorkflowTask",
                web.Lists["Tasks"], web.Lists["workflow History"]
                );
            assoc.AllowManual = true;

            //apply the association to the list
            list.WorkflowAssociations.Add(assoc);

        }
    }
}