Manually start workflow on WebPart Sharepoint 2010

Posted: March 22, 2012 in web
....

  private static void ForceRunWorkflow(SPListItem listitem, string WorkFlowName)
        {

SPSecurity.RunWithElevatedPrivileges(delegate()
{

    SPWorkflowManager wfManager = listitem.Web.Site.WorkflowManager;
    SPWorkflowAssociationCollection spWorkFlows = listitem.ParentList.WorkflowAssociations;
         foreach (SPWorkflowAssociation sendingWF in spWorkFlows)
         {
          if (sendingWF.Name == WorkFlowName.Trim())
          {
            wfManager.StartWorkflow(listitem,sendingWF,
                                    sendingWF.AssociationData, true);
            break;
          }
         }
});

        }

         //handler created to handle the update - and allows use of allowunsafeupdates
        protected void MyHandler(object sender, EventArgs e)
        {
            Page.Validate();
            if (Page.IsValid)
            {
                oWeb.AllowUnsafeUpdates = true;
                context.ListItem.Update();
                ForceRunWorkflow(context.ListItem, WorkFlowName);

...
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s