I was assigned a task to create a simple aspx page where the user could see all the all the different documents, workflows running against them, workflows task information as well as workflow history.
Here we can make use of SPWorkflow and SPWorkflowTask class.
The page would be displaying the information in the following manner
Workflow status for following document :-SampleDocument1
Workflow name :- Approval Workflow
Workflow Task Title
First Team Task
Second Team Task
Third Team Task
Workflow History Description
The approval workflow has started waiting for and Second Team to respond
Task has been created and assigned to First and Second Team
First and Second team has completed their task
Workflow status for following document :- SampleDocument2
Workflow name :- Approval Workflow
Workflow Task Title
First Team Task
Workflow History Description
The approval workflow has started waiting for First and Second Team to respond
The sample code for getting the above information
protected void Page_Load(object sender, EventArgs e)
{
//SPWorkflowManager myWFMgr = new SPWorkflowManager();
SPSite objSite = new SPSite(“http://servername:port”);
SPWeb objWeb = objSite.OpenWeb();
SPList myList = objWeb.Lists[“ListName”];
// for each document within the Library
foreach (SPListItem myListItem in myList.Items)
{
Response.Write(“<b>Workflow status for following document :-</b>” + myListItem[“Title”].ToString());
Response.Write(“</br>”);
// Get the workflows associated
foreach (SPWorkflow myWF in myListItem.Workflows)
{
// Get the name of the workflow
Response.Write(“Workflow name :- “+ myWF.ParentAssociation.Name);
Response.Write(“</br>”);
Response.Write(“<b>Workflow Task Title </b>”);
Response.Write(“</br>”);
// for each workflow running get the workflow tasks and history information
foreach (SPWorkflowTask myWFTask in myWF.Tasks)
{
Response.Write(myWFTask[“Title”].ToString());
Response.Write(“</br>”);
}
// for each workflow running get the history information
Response.Write(“<b>Workflow History Description</b> “);
Response.Write(“</br>”);
SPList myList1 = objWeb.Lists[“Workflow History”];
SPQuery query = new SPQuery();
query.Query = “<OrderBy><FieldRef Name=”ID”/></OrderBy>” +
“<Where><Eq><FieldRef Name=”WorkflowInstance”/>” +
“<Value Type=”Text”>{“ + myWF.InstanceId.ToString() + “}</Value>” +
“</Eq></Where>”;
SPListItemCollection historyListItems = myList1.GetItems(query);
foreach (SPListItem i in historyListItems)
{
Response.Write( i[“Description”].ToString());
Response.Write(“</br>”);
}
}
Response.Write(“</br>”);
}
}
That’s it …
