Feb 7, 2012

Seqential workflow in SharePoint 2010 using Visual studio 2010

Hello guys,

In this article we will work on developing sequential workflow in SharePoint 2010 using Visual studio 2010.
let start creating new project of type Sequential Workflow ,under SharePoint 2010 in Visual studio 2010.

Deploy as form Solution. Click Next

Name workflow as devendra Sequential workflow and select site workflow.
click on Next

CLick Next.

CLick Next.

Click on Finish.
It will show the below project structure.

Go to tool box. Select Create Task under SharePoint workflow

Drag and drop below onworkflowActivated .

Click on the redmark in Createtask1 control

Click on Activity ‘createTask1’ does not have Correlation property set.
Give the Correlation token as Task token.
Select Owner ActivityName as Workflow1.

Click on TaskProperties.Select Bind to new member.
Select create Field. Click OK.

Go to workflow.cs[design] --> right click --> View Code
It will redirect to the code file workflow.cs file you can see the filed you have added just now.
If you check the Bind to existing member you can the Field added it.

Click on TaskID from the properties of CreateTask activity. Select Bind to new member.
Select create Field. Click Ok.
Go to workflow.cs[desgin]-->right click -->View Code
It will redirect to the code file workflow.cs file you can see the filed you have added just now.

Go to Workflow1.cs-Desgin.
Double click on Create Task Activity.It will generate a method called createTask1_MethodInvoking.
Write the below code in the method.

       private void createTask1_MethodInvoking(object sender, EventArgs e)
      createTask1_TaskId1 = Guid.NewGuid();

      createTask1_TaskProperties1.Title = "New Task";
      createTask1_TaskProperties1.Description = "Please complete this ASAP";
      createTask1_TaskProperties1.AssignedTo = workflowProperties.Originator;


The above code create the task for user we runs the workflow.
Go to ToolBox select LogtoHistoryListActivity under Sharepoint workflow

Drag and drop the LogtoHistoryListActivity to workflow.cs[design] file below create task

Click on logToHistoryActivity1 Press F4 to see the properties.
Click on History Description.

Click OK.
Check the properties logToHistoryActivity1

Right click on logToHistoryActivity1.
Click on Generate Handlers.

A method will get generate with the name logToHistoryListActivity1_MethodInvoking
Paste the below code inside the method.
private void logToHistoryListActivity1_MethodInvoking(object sender, EventArgs e)
  logToHistoryListActivity1_HistoryDescription1 = "Work Flow is Running on " + workflowProperties.Web.Url;

Select the project. Right click and Deploy.

Go to Site Actions->View AllsiteContent.

Select Site Workflows.

Click on Devendra Seqential workflow.

Click on status completed.
You can see the web site URL under Description.

You can check the task also has been created in task list for the user who has run the workflow.

Hope you find this useful.

SharePoint-Journey for Administrators, Developers and users