Friday, September 30, 2011

SPWorkflow Status programmatically

I have an document folders which associated with multiple workflows,This code snippet find the specific workflow name and its status.
This code has been developed for my requirement,I need to copy the document to another folder as soon as "Workflow completed".
Associated with List Workflow events in event receiver template.

public override void WorkflowCompleted(SPWorkflowEventProperties properties)
{
using (SPSite site = new SPSite(properties.WebUrl))
{
using (SPWeb web = site.OpenWeb())
{
SPList list = properties.ActivationProperties.List;
foreach (SPListItem item in list.Items)
{
foreach (SPWorkflow wf in item.Workflows)
{

if (list.WorkflowAssociations[wf.AssociationId].Name.ToString() == "MultipleTasksFlow")
{

string WFStatus = item[list.WorkflowAssociations[wf.AssociationId].Name].ToString();

}
}

}

}

}

base.WorkflowCompleted(properties);

}