Un esempio di come avviare un workflow di SharePoint su una lista via codice:

C#

// using Microsoft.SharePoint.Workflow;

string wfName = "nome del workflow";
string listName = "nome lista";

if (string.IsNullOrEmpty(wfName))
{
  throw new ArgumentNullException("Workflow name not defined.");
}

SPWeb web = SPContext.Current.Web;
SPList list = web.Lists[listName];
//cerco il workflow tra quelli associati alla lista
SPWorkflowAssociation wfAassociation = list.WorkflowAssociations.GetAssociationByName(wfName
    , CultureInfo.InvariantCulture);
if (wfAassociation != null)
{
  // se c'è lo avvio
  web.Site.WorkflowManager.StartWorkflow(item, wfAassociation
     , wfAassociation.AssociationData, SPWorkflowRunOptions.Asynchronous);
}  
se invece voglio verificare se su un item c'è un workflow già avviato:

C#

private bool WorkflowIsRunning(SPListItem item)
{
  foreach (SPWorkflow wf in item.Workflows)
  {
    if ((wf.InternalState & SPWorkflowState.Running) == SPWorkflowState.Running)
    {
      return true;
    }
  }
  return false;
}
Tags:
C#235 SharePoint497 SharePoint 2010224 Workflow14
Potrebbe interessarti anche: