Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.84 KB | None | 0 0
  1. var workflowServiceManager = new WorkflowServicesManager(web);
  2. var workflowSubscriptionService = workflowServiceManager.GetWorkflowSubscriptionService();
  3.  
  4.  
  5. //get all workflows associated with the list
  6. var subscriptions = workflowSubscriptionService.EnumerateSubscriptionsByList(list.ID);
  7.  
  8. //run all workflows associated with the list
  9. foreach (var workflowSubscription in subscriptions)
  10. {
  11. //initiation parameters
  12. var inputParameters = new Dictionary<string, object>();
  13.  
  14. workflowServiceManager.GetWorkflowInstanceService().StartWorkflowOnListItem(workflowSubscription, item.ID, inputParameters);
  15. }
  16.  
  17. public override void Execute(Guid targetInstanceId)
  18. {
  19. SPWebApplication webapp = this.Parent as SPWebApplication;
  20. SPSite _site = webapp.Sites["sites/site/"];
  21. SPWeb _web = _site.OpenWeb();
  22. SPUser user = _web.AllUsers[@"i:0#.w|domainuser_name"];
  23. SPUserToken token = user.UserToken;
  24.  
  25. // Obtain a reference to the maagers site collection.
  26. using (SPSite site = new SPSite(_site.Url, token))
  27. {
  28. //Obtain a reference to the managers site.
  29. using (SPWeb web = site.RootWeb)
  30. {
  31. SPList list = web.Lists["List1"];
  32. SPListItemCollection items = list.GetItems();
  33. string workflowName = "MyWorkflowName";
  34.  
  35. foreach (SPListItem item in items)
  36. {
  37. var workflowServiceManager = new Microsoft.SharePoint.WorkflowServices.WorkflowServicesManager(item.Web);
  38. var workflowSubscriptionService = workflowServiceManager.GetWorkflowSubscriptionService();
  39.  
  40. // Get all workflows associated with the list
  41. var subscriptions = workflowSubscriptionService.EnumerateSubscriptionsByList(item.ParentList.ID);
  42.  
  43. // Run all workflows associated with the list
  44. foreach (var workflowSubscription in subscriptions)
  45. {
  46. if (workflowSubscription.Name.Equals(workflowName))
  47. {
  48. // Pass in any initiation parameters
  49. var inputParameters = new Dictionary<string, object>();
  50. workflowServiceManager.GetWorkflowInstanceService().StartWorkflowOnListItem(workflowSubscription, item.ID, inputParameters);
  51. }
  52. }
  53. }
  54. }
  55. }
  56. }
  57.  
  58. https://mysharepoint/sites/site/_layouts/15/userdisp.aspx?id={id}&Force=True
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement