Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var workflowServiceManager = new WorkflowServicesManager(web);
- var workflowSubscriptionService = workflowServiceManager.GetWorkflowSubscriptionService();
- //get all workflows associated with the list
- var subscriptions = workflowSubscriptionService.EnumerateSubscriptionsByList(list.ID);
- //run all workflows associated with the list
- foreach (var workflowSubscription in subscriptions)
- {
- //initiation parameters
- var inputParameters = new Dictionary<string, object>();
- workflowServiceManager.GetWorkflowInstanceService().StartWorkflowOnListItem(workflowSubscription, item.ID, inputParameters);
- }
- public override void Execute(Guid targetInstanceId)
- {
- SPWebApplication webapp = this.Parent as SPWebApplication;
- SPSite _site = webapp.Sites["sites/site/"];
- SPWeb _web = _site.OpenWeb();
- SPUser user = _web.AllUsers[@"i:0#.w|domainuser_name"];
- SPUserToken token = user.UserToken;
- // Obtain a reference to the maagers site collection.
- using (SPSite site = new SPSite(_site.Url, token))
- {
- //Obtain a reference to the managers site.
- using (SPWeb web = site.RootWeb)
- {
- SPList list = web.Lists["List1"];
- SPListItemCollection items = list.GetItems();
- string workflowName = "MyWorkflowName";
- foreach (SPListItem item in items)
- {
- var workflowServiceManager = new Microsoft.SharePoint.WorkflowServices.WorkflowServicesManager(item.Web);
- var workflowSubscriptionService = workflowServiceManager.GetWorkflowSubscriptionService();
- // Get all workflows associated with the list
- var subscriptions = workflowSubscriptionService.EnumerateSubscriptionsByList(item.ParentList.ID);
- // Run all workflows associated with the list
- foreach (var workflowSubscription in subscriptions)
- {
- if (workflowSubscription.Name.Equals(workflowName))
- {
- // Pass in any initiation parameters
- var inputParameters = new Dictionary<string, object>();
- workflowServiceManager.GetWorkflowInstanceService().StartWorkflowOnListItem(workflowSubscription, item.ID, inputParameters);
- }
- }
- }
- }
- }
- }
- https://mysharepoint/sites/site/_layouts/15/userdisp.aspx?id={id}&Force=True
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement