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
In this article we will see how to create a sequential workflow in SharePoint 2010 using VS 2010.
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.
First we need to create a "Status" column with a choice field type with various status options in our document library.
Once the "Status" column was created, the document library will be as shown below:
Open the VS2010 -> Select SharePoint 2010 -> Select the Sequential workflow project type and complete the wizard as shown below.
By default we have the following simple start page:
Just click the OnWorkFlowActivated step and create an event called OnWorkFlowActivated_Invoked:
Double-click the onWorkflowActivated step. It will redirect to the code behind file.
Drag a while loop step from the Tool Box, below the onWorkflowActivated step:
Select the while loop step and in the property window configure the "Condition" as "Code Condition" and create an event called "IsWorkFlowPending".
Place the following in the workflow:
Invoke the "IsWorkFlowPending" method in both the "onWorkflowActivated_Invoked" and the "onWorkflowItemChanged1_Invoked" methods.
Let's deploy the solution and we will check whether or not the workflow is deployed in our document library.
Upload a document and start the workflow:
We will see the workflow status as "InProgress" in the document library.
Edit the task and change the status to Approved. Our workflow status will change to "Completed".
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.
In the code behind file, we will prevent the user from deleting a document if the status is "Pending".
Let's check the code in the UI using a document which is in the InProgress Status and try to delete the document.
If we click ok the document is still in our repository.
Let's make some changes in the code to display a user friendly message:
Now when we try to delete the document we will see the following message.
We created a simple workflow in VS 2010 which prevents the users from deleting a document, if it's not approved.