Kwizcom Forms

Create workflow history list using .Net managed object model code in SharePoint online

sharepoint online create history list using csom

Here we will discuss how we can create a workflow history list using .Net managed object model (C#.Net) code in SharePoint online. Here we are writing the code inside a console application and we are communicating to a SharePoint online (Download PDF for FREE) site. To work with .Net managed object model code we need to add the below two dlls:

  • Microsoft.SharePoint.Client.dll
  • Microsoft.SharePoint.Client.Runtime.dll

Create workflow history list programmatically

Here we are taking both the list title (display name) and name (url). And we are checking if the list exists with the title. If not exists then we are creating the history list. We need to choose the list template as ListTemplateType.WorkflowHistory whose value in 140.

SharePoint deveopment training course

Read: SharePoint Online Create Workflow History List using PowerShell or using SharePoint Designer 2013

public static void CreateWorkflowHistoryList(string siteURL)
{
using (ClientContext ctx = new ClientContext(siteURL))
{
ctx.AuthenticationMode = ClientAuthenticationMode.Default;
ctx.Credentials = new SharePointOnlineCredentials(GetSPOAccountName(), GetSPOSecureStringPassword());
var web = ctx.Web;
ctx.ExecuteQuery();
ListCollection listCollection = ctx.Web.Lists;
var listName = “OurWorkflowHistory”;
var listTitle = “Our Workflow History”;
ctx.Load(listCollection, lists => lists.Include(list => list.Title).Where(list => list.Title == listTitle));
ctx.ExecuteQuery();
if (listCollection.Count > 0)
{
}
else
{
List ourHistoryList;
ListCreationInformation creationInfo = new ListCreationInformation();
creationInfo.Title = listTitle;
creationInfo.Url = listName;
creationInfo.TemplateType = (int)ListTemplateType.WorkflowHistory;
ourHistoryList = ctx.Web.Lists.Add(creationInfo);
ourHistoryList.Update();
ctx.ExecuteQuery();
ctx.Load(ourHistoryList);
ctx.ExecuteQuery();
}
}
}

private static SecureString GetSPOSecureStringPassword()
{
try
{
var secureString = new SecureString();
foreach (char c in ConfigurationManager.AppSettings[“SPOPassword”])
{
secureString.AppendChar(c);
}
return secureString;
}
catch
{
throw;
}
}

private static string GetSPOAccountName()
{
try
{
return ConfigurationManager.AppSettings[“SPOAccount”];
}
catch
{
throw;
}
}

Read some sharepoint online tutorials:

Once you run the code, you can see the history list got created successfully like below:

sharepoint online create history list using csom
sharepoint online create history list using csom

Hope this will be helpful to create a workflow history list using .Net client object model code in SharePoint 2013/2016/Online.

Check out Best Alternative to InfoPath -> Try Now

free sharepoint training

SharePoint Online FREE Training

JOIN a FREE SharePoint Video Course (3 Part Video Series)

envelope
envelope

About Bhawana Rathore

Hello Everyone!! I am Bhawana a SharePoint MVP and having about 8+ years of SharePoint experience as well as in .Net technologies . I have worked in all the versions of SharePoint from wss to Office 365. I have good exposure in Customization and Migration using Nintex, Metalogix tools . Now exploring more in SharePoint 2016 :) Hope here I can contribute and share my knowledge to the fullest. As I believe "There is no wealth like knowledge, and no poverty like ignorance"

View all posts by Bhawana Rathore →