In this SharePoint tutorial, we will discuss, how we can create a workflow using visual studio for SharePoint online site, and also we will see how to deploy the visual studio sharepoint workflow to host web list or library. Let us develop a very simple custom workflow in SharePoint using visual studio.
Since we are going to develop as a SharePoint hosted add-in, make sure you have a developer site is ready which you. You can check an article on how to create a developer site for SharePoint online Office 365.
Create SharePoint workflow visual studio
Follow the below steps to create a SharePoint workflow using visual studio as an add-in and deploy to host web in SharePoint Online Office 365.
Open visual studio 2015/2017 and then File -> New -> Project. And then in the New Project dialog box, choose SharePoint Add-in from Templates -> Visual C# -> Office/SharePoint like below:
Then in the Add-in settings dialog box, give SharePoint online developer site URL and choose the host type for SharePoint Add-in as “SharePoint-hosted“.
Then it will ask for credentials to connect to SharePoint online site. Once entered successfully, it will show the below screen.
Now the SharePoint Add-in project will look like below:
To make the workflow available in the host web we need to choose “Integrated App” project properties to true. But since we have not added Workflow yet, you will not be able to see the “Integrated App” project properties.
Next, we will add a Workflow to the project. Right-click on the Project, Add -> New Item. And in the Add New Item dialog box, choose Visual C# Items -> Office/SharePoint. And then choose the Workflow template like below:
Then in the next screen, give a workflow name and choose List Workflow in the type of workflow like below:
Then in the Select the lists you will use when debugging screen, uncheck the checkbox and do not select anything like below:
Then the workflow will be added to the project and it looks like below:
Now click on F4 in the project to open the Project properties and there change the Integrated App property to True like below:
Now in the workflow search for a WriteToHistory action and click on the Message in the Properties box. There write some message as a string like below:
So this is a very simple workflow having one activity only. Now open the AppManifest.xml file and give Web to manage or full control permission like below:
Now we will try to publish the workflow to the SharePoint online site. Right-click on the Project and click on Publish… like below:
This will open the Publish your add-in page, here click on Package the add-in which will generate the .app file like below:
Now we need to open the .app file using 7-zip or a similar tool like below:
Then open the WorkflowManifest.xml file and check if the below tag is there or not.
<IntegratedApp>true</IntegratedApp>
If not add it and save the file.
Now is time to upload the .app file into the App Catalog site. Once it is uploaded to the App Catalog site, We can add it to any SharePoint site, Site Contents > Add an App > Select your app and add it to your Team Site.
If it asks to trust, Trust it.
Now open any list and from the ribbon click on List Settings -> Workflow Settings and then click on Add a Workflow. On that screen, you will see two options for Available Apps.
One is for This List and another one as your App name (Here in my case it is ApprovalListWFHostWeb).
In the Workflow details Click on the <Workflow Name>(in my case the name is ListApprovalWorkflow) like below:
Then give a name for the workflow and also you can select Task List & History List. Also, choose the Start Options like when you want to start the workflow.
Now if you will again go back to the Workflow settings page, you can see the workflow is attached to the list like below:
Now it is time to start the workflow manually for one item in the list. For this select an item from the list, then click on ECB menu -> Advanced -> Workflows.
Then click on the workflow app and then you can see the workflow under Start a New Workflow like below:
Once the workflow got started successfully, you can see it will write the message which we have added inside the WriteToHistory activity like below:
Send Email using visual studio workflow in SharePoint
Now, let us see another visual studio sharepoint workflow example. Here, we will see how to send an email using visual studio workflow in SharePoint Online.
Follow the above step to first create a custom SharePoint workflow using visual studio.
Once you follow the above article and create your first workflow, the workflow screen will appear like below whereas as a developer you can add activities.
From the toolbox from the left side, I have added two “WriteToHistory” activities from the SP-Utilities section like below. In those “WriteToHistory” activities I have put some messages which will be written to our Workflow History List.
Inside these two activities, I have added one “Email” activity from the SP-Utilities section from the toolbox. The workflow now looks like below:
Here in the above screen, you can see an error mark which is coming because we need to add the mandatory properties inside the Email Activity.
Here if you will look at the properties, you can see there are few optional properties, as well as few Required properties are there. Apart from that Display Name is also there, which we can change.
Here properties like Subject, Body will take string parameters. But properties like To, CC, BCC will take Collection of Strings as a parameter.
So If I will simply put in To as a string like below, it will through me an error.
To resolve this we need to convert the string to a collection of strings. You can write like below:
new System.Collections.ObjectModel.Collection() { "[email protected]"}
The full email properties will look like below:
Here for future propose, I have given Full Control Access in the AppManifest.xml file.
Now right click on the Project -> click on Deploy.
Once it is deployed successfully. It will ask you to trust the App like below. Click on “Trust It”.
Once you trust it, the workflow or the app will be available in all lists and libraries. In my developer site, I have a list name as MyTestList.
Now Open the list and then go to the Workflow Settings page. Here you can see two Apps: This List and [Your App Name]. Click on your App name and then click on Add a workflow.
Here in the Add a Workflow page, It will show you the workflow templates, since I have only one workflow it is showing one. Then give a name for the workflow, choose the Task List, History List, and choose the Start Options for the workflow.
Then click on OK.
Now go back to the list and add one item to the list. Since the workflow will trigger on item add, you can see the details of the workflow.
Click on the … -> Advanced -> Workflows like below:
On the details page, click on your App, then you will be able to see the completed apps like below:
Click on it to see the full details of the workflow. Check out the history list, it has added the messages which we wrote inside the WriteToHistory activity.
Now if you will check the email, you can see the messages like below:
This is how to send email using a custom SharePoint workflow.
Custom workflow in sharepoint 2013 using visual studio – Send email to a group
Now, let us see another example of sharepoint custom workflow using visual studio.
Here we will see how to send email to a SharePoint group using SharePoint custom workflow.
Before proceeding further, follow the above steps to create a sharepoint workflow in visual studio.
Before going further for workflow, I have created a SharePoint group and I have added two users to the SharePoint group.
Now in the workflow when I will send the email, the email should go to all the users presented inside the group. The SharePoint groups look like below:
Once you follow the above article and create your first workflow, the workflow screen will appear like below where as a developer you can add activities.
From the toolbox from the left side, I have added two “WriteToHistory” activities from the SP-Utilities section like below. In those “WriteToHistory” activities I have put some messages which will be written to our Workflow History List.
Inside these two activities, I have added one “Email” activity from the SP-Utilities section from the toolbox. The workflow now looks like below:
Here in the above screen, you can see an error mark which is coming because we need to add the mandatory properties inside the Email Activity.
Here if you will look at the properties, you can see there are few optional properties, as well as few Required properties are there. Apart from that Display Name is also there, which we can change.
Here properties like Subject, Body will take string parameters. But properties like To, CC, BCC will take Collection of Strings as a parameter.
We can send an email to a SharePoint group. But If I will simply put the group name in To as a string like below, it will through me an error.
To resolve this we need to convert the string to a collection of strings. You can write like below:
new System.Collections.ObjectModel.Collection() { "MyCustomSharePointGroup"}
The full email properties will look like below:
Here for future propose, I have given Full Control Access in AppManifest.xml file.
Now right click on the Project -> click on Deploy.
Once it is deployed successfully. It will ask you to trust the App like below. Click on “Trust It“.
Once you trust it, the workflow or the app will be available in all lists and libraries. On my developer site, I have a list name as MyTestList.
Now Open the SharePoint list and then go to the Workflow Settings page. Here you can see two Apps: This List and [Your App Name]. Click on your App name and then click on Add a workflow.
Here in the Add a Workflow page, It will show you the workflow templates, since I have only one workflow it is showing one. Then give a name for the workflow, choose the Task List, History List, and choose the Start Options for the workflow. Then click on OK.
Now go back to the list and add one item to the list. Since the workflow will trigger on item add, you can see the details of the workflow. Click on the … -> Advanced -> Workflows like below:
On the details page, click on your App, then you will be able to see the completed apps like below:
Click on it to see the full details of the workflow. Check out the history list, it has added the messages which we wrote inside the WriteToHistory activity.
Now if you will check the email, you can see the messages like below:
This is how to send email to SharePoint group in visual studio workflow in SharePoint hosted add-in SharePoint online.
Call Web API using httpsend workflow activity in SharePoint Online
Let us see, how we can call a web API from a visual studio workflow by using a httpsend activity in SharePoint Online.
Follow the below step to call web API using httpsend workflow activity in SharePoint Online Visual Studio workflow.
Once the workflow is ready, First, we will create two variables.
- varGetResponseContent (DynamicValue)
- varResult (String)
If you will see the workflow variables it should look like below:
In the workflow, we can access the Web API Url through “HttpSend” workflow activity. Drag and drop a “HttpSend” activity from the Toolbox into the workflow designer interface.
Then in the HttpSend activity properties, choose the below things:
- Method– GET
- RequestHeader:
- Accept (Header Name): “application/json;odata=verbose” (Header Value)
- Content-Type (Header Name): “application/json;odata=verbose” (Header Value)
The RequestHeader looks like below:
Uri: Put the Web API URL. In my case below is the URL:
https://mysharepointwebapi.azurewebsites.net/api/Default/MyAction?testParameter=Bhawana
ResponseContent: varGetResponseContent (Give the DynamicVariable which we have created in the above step).
The properties of HttpSend Activity looks like below:
Now next we will try to retrieve the value which we are getting from the web API.
Now add a GetDynamicValueProperty <T> from the toolbox like below:
First, choose the Type as String in the GetDynamicValueProperty <T> activity like below:
Now in the GetDynamicValueProperty<T> properties, windows choose the below properties:
- Result: varResult (This is the string variable we have created at the beginning)
- Source: varGetResponseContent (Same variable which we have used in ResponseContent in HttpSend activity)
Now we can add a WriteToHistory activity to write the variable value in the SharePoint Workflow History list. It looks like below:
The whole workflow looks like below:
Now our workflow development is ready. We can now deploy and see the result.
Right-click on the project and click on Deploy. Once it is deployed successfully, open any list and from the ribbon, click on Workflow Settings -> Add a workflow.
In the Add workflow page, click on the Workflow Add-in app and then Select the workflow like below:
Then give a name for the workflow, choose the Task list and History list, and check when you want to start the workflow, like below:
Once the workflow is attached to a list, select an item and click on Workflow in the List tab in the ribbon. This will open the page to start a workflow. Click on the workflow link to start the workflow.
Once the workflow is completed, you can see the status like below:
If you will check the details you can see the result like below:
You may like the following SharePoint workflow articles:
- Nintex workflow examples
- SharePoint workflow manager 2019/2016/2013
- How to use App Step Nintex Workflow Action in SharePoint Online Office 365
- How to create provider hosted app in SharePoint Online step by step
- SharePoint event receiver example
In this tutorial, we saw how to develop a visual studio sharepoint workflow and saw a few examples of visual studio sharepoint workflow. I hope it fix the below queries:
- sharepoint custom workflow visual studio
- sharepoint 2013 custom workflow activity visual studio
- creating sharepoint workflow in visual studio
- custom workflow in sharepoint 2013 using visual studio
- creating a custom workflow in sharepoint
- create custom workflow in sharepoint online
- how to create a custom workflow in sharepoint 2013
- how do i create a custom workflow in sharepoint online
- create custom workflow sharepoint 2013
- create custom workflow activity sharepoint 2013 visual studio
After working for more than 15 years in Microsoft technologies like SharePoint, Office 365, and Power Platform (Power Apps, Power Automate, and Power BI), I thought will share my SharePoint expertise knowledge with the world. Our audiences are from the United States, Canada, the United Kingdom, Australia, New Zealand, etc. For my expertise knowledge and SharePoint tutorials, Microsoft has been awarded a Microsoft SharePoint MVP (9 times). I have also worked in companies like HP, TCS, KPIT, etc.