K2 (www.k2.com) is one of the pioneer companies in developing business process management (BPM) solutions. Microsoft products are by heart the foundation of K2 workflow platform. Including .NET 3.0, WWF, WPF, and MOSS 2007. Here, I will demonstrate a very basic walkthrough scenario on using K2BP workflow engine through ASPX pages.
The Scenario
Our walkthough scenario is an approval request for a general message generated by an employee. The employee will submit the form and the manager will either approve or reject it. Finally, the originator “employee” will get a copy of the submitted form.
The Solution
First, we need to build a new empty project from VS2005 File->New. Let’s name it “BasicApproval”

From the Solution Explorer, add a new process from the New Item context menu.

Choose “process” and name it “BasicApprovalProcess.kprx“. Now, Let’s build and design our form that will represent the BasicApproval wrokflow. Basically, we will need three forms to fulfill the process requirements.
- BasicRequest.aspx: The first form that will initiate the process and the employee will create a new process instance from it.
- BasicApproval.aspx: The second form the will be passed to the originator’s manager. The manager will either approve or reject the request.
- BasicApprovalEnd.aspx: The last form that will notify the user of the request result.
Before getting into developing these forms, we need to configure two things. Adding new SourceCode reference and ASPX control. First, right click on the Web Project Icon -> Add Reference -> .NET -> “SourceCode.Workflow.Client”
The second thing is to add the ASPX Control form K2 BlackMarket (www.k2underground.com). Right click on the VS2005 toolbox -> Choose Items -> .NET Framework Components -> Browse -> Choose the downloaded DLL file “blackpearl.web.controls.dll” and then click OK. Here is the result:

It’s time to develop the ASPX forms, each page contains the following controls:
- Subject Textbox: “subject”
- Message Textbox: “message”
BasicRequest.aspx
We need only to add the submit button “K2Submit” to look like this:

Afterwards, add the following code to the submit button’s click event “remember, the code attached is inlined within ASPX tags.”:

BasicApproval.aspx
Copy and paste the old web form and rename it to “BasicApproval.aspx“. Delete the submit button and replace it with the ASPX Control that we’ve added earlier. Rename the ASPX control to “submit” and check the control’s properties to meet the following:

Now, let’s us load the workflow data fields according to the workflow item’s serial key.

Add the following code to the “K2Submit_LoadFields” event:

BasicApprovalEnd.aspx
This form is identical to the “BasicApproval.aspx” form.
It’s show time now!
The earlier steps are very common for any .NET/ASPX developer. From now on, it’s gonna be nasty and really operative. We’ll publish those forms to a web server through FTP “Even that FTP is not secure, I still love it! since you are not concerned about having Front Page Extensions on the target machine”. Then, we are going to design the BasicApprovalProcess in K2 Designer. Afterwards, we will deploy the process and initiate the process as per our plan.
Before you deploy the web forms, you should enable the “identity impersonate” in the web.config as follows:

Don’t forget to deploy/copy the “blackpearl.web.controls.dll” to the bin folder in the target website directory path.
Designing the Process
Let’s get back to our K2 Project. Drop two “Default Client Events” into the designer workspace. Here’s the result:

Activity Configuration
BasicApproval .aspx
Web Form Name: http://ServerName/BasicApproval.aspx
Configure Actions: Add new action, name it “Approval Request”

Configure Outcomes as following and click Finish.

BasicApprovalEnd.aspx
Let’s do the same with this activity according to the following:
Connecting the activities
Now, connect the Start Activity to BasicApproval.aspx Activity (Hold the Ctrl + drag the Start Activity to the BasicApproval.aspx Activity). Also, do the same to the BasicApproval.aspx and BasicApprovalEnd.aspx activities.

Defining the Data Fields
To map our fields in our web forms, we have to define them first in the K2 Data Fields. From the project workspace (I know that sometimes I use Java terminologies in .NET environment..), view -> K2 Object Browser -> Data Fields -> BasicApprovalProcess -> right click and “Add” -> create the two fields as string “subject” and “message“.

I guess that we’re ready now to deploy and test the process. Right click on the Solution’s Name “BasicApproval” and choose Deploy. As I always do, click Finish directly in the deployment wizard…
Testing the process
The testing process will start by creating a new instance using the first web form “BasicRequest.aspx”. After that, a work item should be created for the destination user, K2 Workspace can view and operate all these information. The second step is to proceed the process and approve the work item “BasicApproval.aspx“, last thing is to check the returned result “BasicApprovalEnd.aspx“.

After you submit the form, check the work item flow from the “View Flow” option in Work Item Context Menu in the K2 Workspace


Now, let’s Submit and Approve the “BasicApproval.aspx” form.

The worklist should be updated to reflect the latest activity in the process.

Last Form to submit is “BasicApprovalEnd.aspx”

Let’s check the process flow after completing all activities.

Conclusion
K2BP is a helluva BPM solution!. I’ve only scratched the basics of developing, deploying and testing a very simplified workflow process. K2BP can extend these capabilities to integrate with Microsoft Exchange, Office, InfoPath, BizTalk, LCS, Visio and SharePoint.