How to start your Workflow manually in Sharepoint?

This code snippet discusses how to manually start a workflow in Sharepoint from your code.

SPWorkflowManager.StartWorkflow method is used to start a workflow dynamically from your code.

The following code creates a SPListItem instance and passes it as a parameter in the StartWorkflow method.

SPListItem currentItem = //Your Item To start the workflow on it;
currentItem.Web.AllowUnsafeUpdates = true;

SPWorkflowManager wfManager = currentItem.Web.Site.WorkflowManager;

SPWorkflowAssociationCollection wfAssociation=

foreach (SPWorkflowAssociation Association in wfAssociation)
  if (Association.Name == "WorkflowName")
    wfManager.StartWorkflow(currentItem, Association,Association.AssociationData);break;

Try this.

One more thing you want to keep in mind that you cannot start a workflow from another workflow. You must postback to start the workflow or you can simply create a button on an ASP.NET page and call this code on the button click event handler.