Click here to Skip to main content
15,878,048 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
SQL
I want to start an approval workflow on the click of a button. I need to set all the parameters of the workflow, and its approver, everything programatically. Can anyone help me with this please?

I am very new to SharePoint and do not have SharePoint installed on my computer. I have access to a SharePoint site and I'm trying to learn SP through it.
Posted
Comments
Nathan Minier 4-Sep-14 11:25am    
If you're trying to develop a web part or extension for SharePoint, you must have it installed on the same machine as VS. VS must be 2010/12/13 Professional+. I don't know of a way around these requirements.

The MS reference for SharPoint development on Visual Studio is here:
http://msdn.microsoft.com/en-us/library/ee330921.aspx

1 solution

You can either use the Server-side object model, allowing you to run the application only on the same server that has Sharepoint installed, or the client object model, which you can run from anywhere.

There are different version of the client object model for JavaScript, SilverLight, Mobile and Managed use. From a C# client application, you'll probably need the Managed version. Those assemblies can be found in the ISAPI folder of your Sharepoint installation, and can be copied to your Visual Studio environment to reference.

Using the Object Model, you are going to access the correct list that has the approval workflow attached to it, find the attached workflow, and start it.

I don't have a complete code sample, but it should give you an idea:
C#
ClientContext context = new ClientContext("http://SiteUrl"); 

// The SharePoint web at the URL.
Web web = context.Web; 

// The list with the WF attached
List list = web.Lists.GetByTitle("My List");

var workflowManager = context.Current.Site.WorkflowManager; // untested
var workflowAssociations = list.WorkflowAssociations; // untested

I don't have a working environment with all the SP references here, so the last two lines are untested.
Also, you need to find the approval workflow in the list of WorkflowAssocations (by GUID or name, I'm not sure? sorry, no code sample).
Then use the WorkflowManager to start the Workflow with the right AssociationData (sorry, no code sample)
 
Share this answer
 
Comments
Mausumi Mohandas 5-Sep-14 1:34am    
Thank you so much for the solution. I have added Sharepoint dll's as reference to my VS environment and have found my workflow by GUID also. But I don't know how to set the approver. Could you please help me with this
kbrandwijk 5-Sep-14 17:33pm    
If you start the Workflow using something similar to workflowServiceManager.GetWorkflowInstanceService().StartWorkflowOnListItem(workflowSubscription, itemId, inputParameters); then you can pass the inputparameters as dictionary. You have to find out what the input parameters are exactly for an approval workflow. If you can debug, you can check what is inside the workflowAssocation.AssociationData, since that's what you're passing is as inputParameters normally.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900