Get Workflow Status Programmatically in SharePoint Using Client Side Object Model C#

This post explains how to get SharePoint list item’s workflow status using Client Side Object Model programming, using the below code we can find workflow status id. Because workflow status field internally save the workflow status id only not as name,

List oList = clientContext.Web.Lists.GetByTitle("Documents");
ListItem item = oList.GetItemById(14);
Field workflowStatusField = item.ParentList.Fields.GetByTitle("WorkflowName");
var workflowStatusValue = item[workflowStatusField.InternalName];

In that code workflowStatusValue receive a status id as a list item workflow status. Here I’ve listed workflow status code and their status,

NotStarted = 0
FailedOnStart = 1
InProgress = 2
ErrorOccurred = 3
StoppedByUser = 4
Completed = 5
FailedOnStartRetrying = 6
ErrorOccurredRetrying = 7
ViewQueryOverflow = 8
Canceled = 15
Approved = 16
Rejected = 17

for testing I have created a workflow, named as “WorkflowName” and assigned to one document.


In the below screenshot we can see that the code returns 2, which means workflow status is in-progress.


Feel free to contact me if you have any doubts and queries through comments.

QR Code Generator Add-In for SharePoint

Using this you can generate QR Code for any text value and URL, this add-in can be add anywhere in you SharePoint Dashboard. Below you can see step by step instructions to develop this SharePoint Add-In. Also the complete project source code is available for download, find the download link at the bottom of this post.


Create new Project in Visual studio using “App for SharePoint” template, here I’m using visual studio 2015 version. In the new project wizard select SharePoint-Hosted and rest you can select based on your requirements. Provider-Hosted application can also be selected.
I’ve added two JS files qr.js and initstrings.js, these JS files are developed by Microsoft. Here I modified those files. Modified files can be found in the project.

Add new “Client Web Part (Host Web)” and select “Create a new app web page for the client web part content”, Edit newly created aspx page which is located in the Pages folder. Add below JS code and HTML. In the JS function I am passing Textbox value and Div name as parameter, JavaScript will generate QR code based on the content in Text box value.

 <script type="text/javascript">
 function generatefn() {
 if ($('#QR_URL').val() != '')
 onLoadQrCode($('#QR_URL').val(), 'DivImage');
 <input type="text" id="QR_URL" value="" style="width:250px" /><input onclick="generatefn()" type="button" id="btnGenerate" value="Generate" />
<div id="DivImage"></div>

Project source Download link


Provider Hosted App For SharePoint Online

Create a new project in visual studio using “App for SharePoint” template, here I’m using visual studio 2015 version. After selected project can see a wizard


Enter SharePoint online URL and select “Provider-Hosted” option next it will ask for user name and password, then wizard will automatically select “SharePoint Online” Option


Next select ASP.Net MVC Web Application in the wizard


Next leave by default selection of “Use Windows Azure Access Control Service (for SharePoint Cloud Apps)” then finish the wizard.

Create new razor view under home view folder


Add new ActionResult in HomeController.cs, below code will retrieve list items from the “Shared Documents” and generates a DataTable. pass the DataTable to View.

 public ActionResult DocumentList()
DataTable dt = new DataTable();
var spContext = SharePointContextProvider.Current.GetSharePointContext(HttpContext);
using (var clientcontext = spContext.CreateUserClientContextForSPHost())
List list = clientcontext.Web.GetList(spContext.SPHostUrl.ToString() + "Shared Documents");
CamlQuery cq = new CamlQuery();
ListItemCollection lic = list.GetItems(cq);
clientcontext.Load(lic, items => items.Take(15).Include(item => item["FileLeafRef"], item => item["Modified"],
item => item["Author"], item => item["FileRef"], item => item["File_x0020_Size"]));
dt.Columns.Add("File Name");
dt.Columns.Add("Modified", typeof(DateTime));

foreach (ListItem item in lic)
DataRow dr = dt.NewRow();
dr["File Name"] = "<a href=\"" + spContext.SPHostUrl.ToString().TrimEnd('/') + item["FileRef"]
+ "\">" + item["FileLeafRef"] + "</a>";
dr["Modified"] = item["Modified"];
dr["Author"] = ((FieldUserValue)item["Author"]).LookupValue;
dr["Size"] = item["File_x0020_Size"];

return View(dt);

Add below code to your new view, code will generate a HTML table using our ModelTable.

<div style="padding:5px 10px 3px 5px">
<table border="1" cellpadding="5" id="my-table">
@foreach (System.Data.DataColumn col in Model.Columns)
@foreach (System.Data.DataRow row in Model.Rows)
@foreach (var cell in row.ItemArray)

View name and action result name should be same else mention the view name in the return statement of action result.

In the AppManifest file select the permissions tab and Scope as list and permission as Read


Run the project in visual studio using play button (F5), now can see SharePoint App Permission approval page, select Documents list then click “Trust it”


After that SharePoint will redirect to our local hosted site, navigate to newly created view page. Page will display SharePoint list data.


You can now compare your retrieved data with the actual SharePoint list.