Simple workflow
Aspnet is the document where the user will submit the document which has to undergo approval process
Fig1
After uploded the document the user creates the workflow manually.
When the workflow is triggered it is opening the submitter form. In Which the user will provide the document title, description and comments.
The task will be removed from the approvers work list after he/she completed the task
Association Form.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using SourceCode.Workflow.Client;
namespace DocumentApprovalScenario1
{
public partial class _Default : System.Web.UI.Page
{ protected void Page_Load(object sender, EventArgs e)
{ }
protected void btnSubmit_Click(object sender, EventArgs e)
{
string serverName = "BLACKPEARL";
string processName = "K2DocApprovalAspxForm\\SimpleDocumentApproval";
SourceCode.Workflow.Client.Connection connection = new SourceCode.Workflow.Client.Connection();
//open connection to K2 server
connection.Open(serverName);
//create process instance
ProcessInstance processInstance = connection.CreateProcessInstance(processName);
//populate data fields
processInstance.DataFields["DocTitile"].Value = txtdocTitle.Text;
processInstance.DataFields["DocDescription"].Value = txtdocDescription.Text;
processInstance.DataFields["DocApprover"].Value = txtApprover.Text;
processInstance.DataFields["SubmitterComments"].Value = txtSubmitterComments.Text;
//set process folio
//processInstance.Folio = "Sri's Document Approval " + System.DateTime.Today.ToString();
processInstance.Folio = txtdocTitle.Text + System.DateTime.Today.ToString();
//start the process
connection.StartProcessInstance(processInstance);
//close the connection
connection.Close();
}
}
}
TaskForm.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using SourceCode.Workflow.Client;
using SourceCode.Hosting.Client;
namespace DocumentApprovalScenario1
{
public partial class WebForm1 : System.Web.UI.Page
{
string _SN;
protected void Page_Load(object sender, EventArgs e)
{
_SN = Request.QueryString["SN"];
lblSerialNo.Text = _SN.ToString(); }
protected void btnOk_Click(object sender, EventArgs e)
{
// TODO: Replace these placeholder values with values for your environment
string _serverName = "BLACKPEARL";
string _user = "ddd"";
string _domain = "xxx";
string _password = "Xx
string _wfSerialNumber = _SN;
string _action = "Approve";
SourceCode.Hosting.Client.BaseAPI.SCConnectionStringBuilder connectionString = new SourceCode.Hosting.Client.BaseAPI.SCConnectionStringBuilder();
connectionString.Host = "localhost";
connectionString.Integrated = true;
connectionString.IsPrimaryLogin = true;
connectionString.Port = 5252;
connectionString.UserID = _user;
connectionString.WindowsDomain = _domain;
connectionString.Password = _password;
connectionString.SecurityLabelName = "K2"; //the default label
lblApprover.Text = _user.ToString();
// open a K2 connection
Connection connection = new Connection();
connection.Open(_serverName, connectionString.ToString());
// loop through each worklist item
foreach (WorklistItem worklistItem in connection.OpenWorklist())
{
// open the worklist item
connection.OpenWorklistItem(worklistItem.SerialNumber);
if (worklistItem != null && worklistItem.SerialNumber == _wfSerialNumber)
{
// action the workflow by looping through to find the
// right action (you must know the action name)
foreach (Action action in worklistItem.Actions)
{
if (action.Name == _action)
{
action.Execute();
}
}
}
}
}
}
}
Share point Workflow Integration wizard screen shots
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using SourceCode.Workflow.Client;
namespace DocumentApprovalScenario1
{
public partial class _Default : System.Web.UI.Page
{ protected void Page_Load(object sender, EventArgs e)
{ }
protected void btnSubmit_Click(object sender, EventArgs e)
{
string serverName = "BLACKPEARL";
string processName = "K2DocApprovalAspxForm\\SimpleDocumentApproval";
SourceCode.Workflow.Client.Connection connection = new SourceCode.Workflow.Client.Connection();
//open connection to K2 server
connection.Open(serverName);
//create process instance
ProcessInstance processInstance = connection.CreateProcessInstance(processName);
//populate data fields
processInstance.DataFields["DocTitile"].Value = txtdocTitle.Text;
processInstance.DataFields["DocDescription"].Value = txtdocDescription.Text;
processInstance.DataFields["DocApprover"].Value = txtApprover.Text;
processInstance.DataFields["SubmitterComments"].Value = txtSubmitterComments.Text;
//set process folio
//processInstance.Folio = "Sri's Document Approval " + System.DateTime.Today.ToString();
processInstance.Folio = txtdocTitle.Text + System.DateTime.Today.ToString();
//start the process
connection.StartProcessInstance(processInstance);
//close the connection
connection.Close();
}
}
}
TaskForm.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using SourceCode.Workflow.Client;
using SourceCode.Hosting.Client;
namespace DocumentApprovalScenario1
{
public partial class WebForm1 : System.Web.UI.Page
{
string _SN;
protected void Page_Load(object sender, EventArgs e)
{
_SN = Request.QueryString["SN"];
lblSerialNo.Text = _SN.ToString(); }
protected void btnOk_Click(object sender, EventArgs e)
{
// TODO: Replace these placeholder values with values for your environment
string _serverName = "BLACKPEARL";
string _user = "ddd"";
string _domain = "xxx";
string _password = "Xx
string _wfSerialNumber = _SN;
string _action = "Approve";
SourceCode.Hosting.Client.BaseAPI.SCConnectionStringBuilder connectionString = new SourceCode.Hosting.Client.BaseAPI.SCConnectionStringBuilder();
connectionString.Host = "localhost";
connectionString.Integrated = true;
connectionString.IsPrimaryLogin = true;
connectionString.Port = 5252;
connectionString.UserID = _user;
connectionString.WindowsDomain = _domain;
connectionString.Password = _password;
connectionString.SecurityLabelName = "K2"; //the default label
lblApprover.Text = _user.ToString();
// open a K2 connection
Connection connection = new Connection();
connection.Open(_serverName, connectionString.ToString());
// loop through each worklist item
foreach (WorklistItem worklistItem in connection.OpenWorklist())
{
// open the worklist item
connection.OpenWorklistItem(worklistItem.SerialNumber);
if (worklistItem != null && worklistItem.SerialNumber == _wfSerialNumber)
{
// action the workflow by looping through to find the
// right action (you must know the action name)
foreach (Action action in worklistItem.Actions)
{
if (action.Name == _action)
{
action.Execute();
}
}
}
}
}
}
}
Share point Workflow Integration wizard screen shots