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 …
Discover more from Nishant Rana's Weblog
Subscribe to get the latest posts sent to your email.

Thank you so much I have been looking for a code sample like this!!
LikeLike
Is there any solution for speed up the data fetching in wss 3.O web services methods ,
Actually fetching data through web services from wss3.0 is very very slow..how can I improve its performance ..pls suggest me .
LikeLike
Hi Avinash,
For Web Services in CRM we do the following
http://msdn.microsoft.com/en-us/library/ee704594.aspx
I guess you could try the same for wss web services i.e. creating a pre generated xml serialzer for that.
http://uwekaessner.spaces.live.com/blog/cns!21916E8556D908E!175.entry?sa=260352433
Regards,
Nishant Rana
LikeLike
Great Post !
LikeLike