Using Workflow Object Model in SharePoint.

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 …


Author: Nishant Rana

I love working in and sharing everything about Microsoft.NET technology !

6 thoughts on “Using Workflow Object Model in SharePoint.”

  1. 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 .

    Like

Share your thoughts

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s