Cancel the Workflow Through Object Model

Cancel the Workflow Through Object Model



using (SPSite osite = new SPSite(SPContext.Current.Site.ID))


using (SPWeb oweb = osite.OpenWeb(SPContext.Current.Web.ID))


SPList oList= oweb.Lists[“List Name”];

SPListItem olstitem = oTravelRequestList.GetItemById(133);

SPWorkflowManager manager = osite.WorkflowManager;

foreach (SPWorkflow itemWorkflow in manager.GetItemActiveWorkflows(olstitem))


MainDataSource.CreateNavigator().SelectSingleNode(“/my:myFields/my:txtNotes”, NamespaceManager).SetValue(“Title is” + manager.GetItemActiveWorkflows(olstitem).Count);

oweb.AllowUnsafeUpdates = true;


SPWorkflowHistoryEventType.WorkflowCancelled, 0, oweb.CurrentUser , “Cancelled by the User”, “Cancelled By Siva”, null);

oweb.AllowUnsafeUpdates = false;

if (!itemWorkflow.IsLocked)

{                                     foreach (SPWorkflowTask taskWorkflow in itemWorkflow.Tasks)                                     {

taskWorkflow[“Status”] = “Canceled”;                                         oweb.AllowUnsafeUpdates = true;


oweb.AllowUnsafeUpdates = false;


oweb.AllowUnsafeUpdates = true;

SPWorkflowManager.CancelWorkflow(itemWorkflow);                                     oweb.AllowUnsafeUpdates = false;







About sharepointsriram

9+ Yrs of IT experience
This entry was posted in Sharepoint 2010 Workflow. Bookmark the permalink.

Leave a Reply

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

You are commenting using your 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