SPSecurity.RunWithElevatedPrivileges(delegate()
{
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;
itemWorkflow.CreateHistoryEvent((int)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;
taskWorkflow.SystemUpdate();
oweb.AllowUnsafeUpdates = false;
}
oweb.AllowUnsafeUpdates = true;
SPWorkflowManager.CancelWorkflow(itemWorkflow);
oweb.AllowUnsafeUpdates = false;
}
}
}
}
});
Comments
Post a Comment