Navigate Up
Sign In
Supporters of Developer
Web

Sequential Workflow in SharePoint 2010 Using Visual Studio 2010

Item is currently unrated. Press SHIFT+ENTER to rate this item.1 star selected. Press SHIFT+ENTER to submit. Press TAB to increase rating. Press SHIFT+ESCAPE to leave rating submit mode.2 stars selected. Press SHIFT+ENTER to submit. Press TAB to increase rating. Press SHIFT+TAB to decrease rating. Press SHIFT+ESCAPE to leave rating submit mode.3 stars selected. Press SHIFT+ENTER to submit. Press TAB to increase rating. Press SHIFT+TAB to decrease rating. Press SHIFT+ESCAPE to leave rating submit mode.4 stars selected. Press SHIFT+ENTER to submit. Press TAB to increase rating. Press SHIFT+TAB to decrease rating. Press SHIFT+ESCAPE to leave rating submit mode.5 stars selected. Press SHIFT+ENTER to submit. Press SHIFT+TAB to decrease rating. Press SHIFT+ESCAPE to leave rating submit mode.

You may also be interested in: SharePoint Services with mindfiresolutions

 

Editor's note: Contributor Venkatesh Kumar is a Senior Developer for Cognizant. Follow him @venkat_mru

Introduction

In this article we will see how to create a sequential workflow in SharePoint 2010 using VS 2010.

Objective

Let's make the scenario simple. We want to create a simple workflow and if the workflow status is not completed, we need to prevent the user from deleting the document.

Steps

First we need to create a "Status" column with a choice field type with various status options in our document library.

2012-12-19-SequentialWorkflow-01.jpg

Once the "Status" column was created, the document library will be as shown below:

2012-12-19-SequentialWorkflow-02.jpg

Open the VS2010 -> Select SharePoint 2010 -> Select the Sequential workflow project type and complete the wizard as shown below.

2012-12-19-SequentialWorkflow-03.jpg

2012-12-19-SequentialWorkflow-04.jpg

By default we have the following simple start page:

2012-12-19-SequentialWorkflow-05.jpg

Just click the OnWorkFlowActivated step and create an event called OnWorkFlowActivated_Invoked:

2012-12-19-SequentialWorkflow-06.jpg

Double-click the onWorkflowActivated step. It will redirect to the code behind file.

2012-12-19-SequentialWorkflow-07.jpg

Drag a while loop step from the Tool Box, below the onWorkflowActivated step:

2012-12-19-SequentialWorkflow-08.jpg

2012-12-19-SequentialWorkflow-09.jpg

Select the while loop step and in the property window configure the "Condition" as "Code Condition" and create an event called "IsWorkFlowPending".

2012-12-19-SequentialWorkflow-10.jpg

2012-12-19-SequentialWorkflow-11.jpg

2012-12-19-SequentialWorkflow-12.jpg

2012-12-19-SequentialWorkflow-13.jpg

2012-12-19-SequentialWorkflow-14.jpg

2012-12-19-SequentialWorkflow-15.jpg

Place the following in the workflow:

2012-12-19-SequentialWorkflow-16.jpg

Invoke the "IsWorkFlowPending" method in both the "onWorkflowActivated_Invoked" and the "onWorkflowItemChanged1_Invoked" methods.

2012-12-19-SequentialWorkflow-17.jpg

Let's deploy the solution and we will check whether or not the workflow is deployed in our document library.

2012-12-19-SequentialWorkflow-18.jpg

Upload a document and start the workflow:

2012-12-19-SequentialWorkflow-19.jpg

We will see the workflow status as "InProgress" in the document library.

2012-12-19-SequentialWorkflow-20.jpg

Edit the task and change the status to Approved. Our workflow status will change to "Completed".

2012-12-19-SequentialWorkflow-21.jpg

We can prevent the user from "Deleting" the document, if the "Status" is not completed. Just add an Event Receiver in the same workflow project.

2012-12-19-SequentialWorkflow-22.jpg

2012-12-19-SequentialWorkflow-23.jpg

In the code behind file, we will prevent the user from deleting a document if the status is "Pending".

2012-12-19-SequentialWorkflow-24.jpg

Let's check the code in the UI using a document which is in the InProgress Status and try to delete the document.

2012-12-19-SequentialWorkflow-25.jpg

If we click ok the document is still in our repository.

2012-12-19-SequentialWorkflow-26.jpg

Let's make some changes in the code to display a user friendly message:

2012-12-19-SequentialWorkflow-27.jpg

Now when we try to delete the document we will see the following message.

2012-12-19-SequentialWorkflow-28.jpg

Summary

We created a simple workflow in VS 2010 which prevents the users from deleting a document, if it's not approved.

References

http://msdn.microsoft.com/en-us/library/hh237664(v=office.14).aspx
http://msdn.microsoft.com/en-us/office2010developertrainingcourse_vs2010sharepointworkflow.aspx

Categories: dev; Visual Studio; Visual Studio 2010; Workflow; 2010

Comments

Kevin

IsWorkFlowPending

This method name makes sense but your variable is called "isWorkFlowApproved" and then the logic is for whether the workflow is pending.
 
Having said that, this is the best, "how to do it" explanation for a simple, useful SharePoint Sequential Workflow I've seen.
 
Thanks.

Posted 21-Dec-2012 by Kevin
john

editing

In the cipher simple transcribe, editing manuscripts we wish prevent the user from deleting a bargain if the status is "Pending".

Posted 22-Sep-2013 by john
conversion rate optimization services

In this article

In this article we will discuss the SharePoint 2013 User Profile Properties and their uses in detail.

xcxbcxb

ccccccccccccc

Although Rep Todd Akins went out of his way to create a deceive of himself regarding his information of females and sex, he is not very far eliminated from the Republican Person's anit-woman mind-set. It is one that provide you the sensation they would like to recover to them their position in community as it was in the beginning Nineteenth Millennium. CostcoCarCar.com

Posted 23-Nov-2013 by xcxbcxb
sairam niluroutu

Mistake

Invoke the "CheckworkflowStatus" not "IsWorkFlowPending" method in both the "onWorkflowActivated_Invoked" and the "onWorkflowItemChanged1_Invoked" methods

Posted 12-Feb-2014 by sairam niluroutu

Notify me of comments to this article

E-mail:
   

Add Comment

Title:

 
Comment:
Email:

   


Name:

 
Url: