I have added a state machine WF in VS by right clicking my solution and Add -> Add New Item -> then under "Office/SharePoint I added the "State Machine WF (Farm Solution Only). So the WF is now part of the solution along with my form and code behind. I have not wired up the submit button to "Start" the WF, because I am unsure of how to do it. I have been looking online for any good leads on this and have been unable to find anything that helps with my issue.

My form is developed in asp.net, my code behind is vb.net and I added my state machine WF to the same solution. I then deployed my form, code behind and WF into SharePoint via an Application Page (Farm Solution only) in Visual Studio 2013.

Could someone please provide me with any good advice or articles that relate and solve this issue? Maybe I am approaching this from the wrong direction... I am open to any opinions of others.

Thank you


Here is a snippet which I created for one of my recent project

public void StartWorkFlow(string strListName, int intCurrentItemID, string strWorkflowName)
        using (SPSite objSite = new SPSite(SPContext.Current.Site.Url))
            using (SPWeb objWeb = objSite.OpenWeb())
                objWeb.AllowUnsafeUpdates = true;
                //get list
                SPList list = objWeb.Lists[strListName];
                //get list item
                SPListItem lstItem = list.GetItemById(intCurrentItemID);
                //obtain an instance of SPWorkflowManager which will be used to start the workflow
                SPWorkflowManager manager = objSite.WorkflowManager;
                //get all workflows associated with the list
                SPWorkflowAssociationCollection associationCol = list.WorkflowAssociations;
                //iterate through all the workflow and lookup for the workflow to be started
                foreach (SPWorkflowAssociation association in associationCol)
                    if (association.Name == strWorkflowName)
                        //get workflow association data
                        string associationData = association.AssociationData;
                        //start the workflow
                        manager.StartWorkflow(lstItem, association, associationData);                                
                objWeb.AllowUnsafeUpdates = false;
  • I am not really following this... is this creating the WF programmatically? I have already developed my WF, I just need it to fire on button click.. Oct 27 '14 at 18:17
  • This is a code snippet for starting a workflow. On button click call the Method StartWorkflow and pass the parameters. Oct 27 '14 at 18:18
  • Ok, so what exactly are the parameters strListName, intCurrenItemID, and strWorkflowName? Oct 27 '14 at 18:21
  • strListName - Name of the list where the workflow is associated. intCurrentItemID - Item Id on which the workflow is to be started. strWorkflowName - Name of the workflow Oct 27 '14 at 18:23
  • See my WF isn't associated with a list... it is based on an asp.net web form Oct 27 '14 at 18:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.