Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.14 KB | None | 0 0
  1. using (SPSite site = new SPSite(url))
  2. {
  3. using (SPWeb oWeb = site.OpenWeb())
  4. {
  5. var workflowServiceManager = new WorkflowServicesManager(oWeb);
  6. var workflowSubscriptionService = workflowServiceManager.GetWorkflowSubscriptionService();
  7.  
  8. //get all workflows associated with the list
  9. var subscriptions = workflowSubscriptionService.EnumerateSubscriptionsByList(list.ID);
  10.  
  11. foreach (var workflowSubscription in subscriptions)
  12. {
  13.  
  14. var inputParameters = new Dictionary<string, object>();
  15.  
  16.  
  17. WorkflowInstanceService instanceService = workflowServiceManager.GetWorkflowInstanceService();
  18.  
  19. if (instanceService != null)
  20. {
  21. foreach (WorkflowInstance wfInstance in instanceService.EnumerateInstancesForListItem(list.ID, currentItem.ID))
  22. {
  23. SPWorkflow wf = new SPWorkflow(currentItem, wfInstance.Id);
  24. }
  25. }
  26. }
  27.  
  28. SPWorkflowManager spWorkflowManager = site.WorkflowManager;
  29. SPWorkflowFilter filter = new SPWorkflowFilter();
  30.  
  31. filter.InclusiveFilterStates = SPWorkflowState.Running;
  32.  
  33. SPWorkflowTaskCollection workTaskColl = oWeb.Site.WorkflowManager.GetItemTasks(currentItem, filter);
  34.  
  35. foreach (SPWorkflowTask task in workTaskColl)
  36. {
  37. }
  38.  
  39. foreach (SPWorkflow workflow in spWorkflowManager.GetItemActiveWorkflows(currentItem))
  40. {
  41. foreach (SPWorkflowTask t in workflow.Tasks)
  42. {
  43. }
  44. }
  45.  
  46. foreach (SPWorkflow instance in spWorkflowManager.GetItemWorkflows(currentItem))
  47. {
  48.  
  49.  
  50. }
  51. }
  52. }
  53.  
  54. using (SPSite mySite = new SPSite(SPContext.Current.Web.Url))
  55. {
  56. using (SPWeb myWeb = mySite.OpenWeb())
  57. {
  58. var filteredtaskItem = (from SPListItem itm in myWeb.Lists.TryGetList("TaskListName").Items
  59. where GetRelatedItem2(myWeb, itm["Related Items"].ToString() + "") == itemID.ToString()
  60. select itm).ToList();
  61.  
  62.  
  63. foreach (SPListItem item in filteredtaskItem)
  64. {
  65. }
  66. }
  67. }
  68.  
  69.  
  70. public string GetRelatedItem2(SPWeb web, string relatedItems)
  71. {
  72. string itemID = string.Empty;
  73. relatedItems = relatedItems.Trim(new char[] { '[', '{', '}', ']' });
  74. string[] relatedItemsVals = relatedItems.Split(',');
  75. Dictionary<string, string> items = new Dictionary<string, string>();
  76. foreach (var itemsVal in relatedItemsVals)
  77. {
  78. string[] keyval = itemsVal.Split(':');
  79. items[keyval[0].Trim('"')] = keyval[1].Trim('"');
  80. }
  81.  
  82. string itemIDStr = items["ItemId"];
  83. string listIDStr = items["ListId"];
  84. Guid listID = new Guid(listIDStr);
  85. SPList itemList = web.Lists[listID];
  86. SPItem item = null;
  87. try
  88. {
  89. item = itemList.GetItemById(int.Parse(itemIDStr));
  90. if (item != null)
  91. {
  92. itemID = item["ID"].ToString();
  93. }
  94. }
  95. catch (Exception ex)
  96. {
  97.  
  98. itemID = string.Empty;
  99. }
  100. //SPItem item = itemList.GetItemById(int.Parse(itemIDStr));
  101. return itemID;
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement