Lucy de Boer
 

Start worklfow from code

07

Mar

I wrote an eventhandler which needs to update a publishingpage to the next minor version and (re)start a workflow from code.

Cleaning up any running workflows of the same type will prevent 'Exception from HRESULT: 0x8102009B'.

foreach (SPWorkflowAssociation wfAssoc in item.ContentType.WorkflowAssociations)
       {
// search workflowassociation by name
        if ((wfAssoc.Name.ToLower().Contains("controleren")) && (wfAssoc.Name.ToLower().Contains("publicatie")))
        {
// check current item for running workflows of the same type
         foreach(SPWorkflow wf in item.Workflows)
         {
          if (wf.ParentAssociation.Name.Equals(wfAssoc.Name))
          {
// remove running workflow
           item.Web.Site.WorkflowManager.RemoveWorkflowFromListItem(wf);
          }
         }
// start workflow
         item.Web.Site.WorkflowManager.StartWorkflow(item, wfAssoc, wfAssoc.AssociationData);
         break;
        }
       }

 

Categorie: SharePoint, Workflow
Share:

Lucy de Boer schreef

Comments (0) | Permalink

Lucy de Boer
Comments are closed.

Zoeken

Categorie

Archief


Sign In