Activate SharePoint Workflows can use app permissions Feature programmatically

In this SharePoint tutorial, we will see how to activate “Workflows can use app permissions” in SharePoint online site programmatically using client object model code (csom).

We will use C#.net managed object model code (Microsoft.SharePoint.Client.dll) to activate the workflows can use app permissions.

“Workflows can use app permissions” is site level feature and the feature id for this feature is: “ec918931-c874-4033-bd09-4f36b2e31fef“.

You can check out this MSDN article for know more about the feature id for various out of box features in SharePoint 2013.

Even if you have any issues like “workflows can use app permissions error activating“, you can also use CSOM to activate the feature.

Activate workflows can use app permissions

Below is the full code to activate workflows can use app permissions.

public static void ActivateWorkflowFeature(string siteURL)
{
Guid WebFeatureID = Guid.Parse(“ec918931-c874-4033-bd09-4f36b2e31fef”);
using (ClientContext ctx = new ClientContext(siteURL))
{
ctx.AuthenticationMode = ClientAuthenticationMode.Default;
ctx.Credentials = new SharePointOnlineCredentials(GetSPOAccountName(), GetSPOSecureStringPassword());
var web = ctx.Web;
ctx.Load(web);
ctx.ExecuteQuery();
var webFeatures = ctx.Web.Features;
ctx.Load(webFeatures);
ctx.ExecuteQuery();
webFeatures.Add(WebFeatureID, true, FeatureDefinitionScope.None);
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;
}
}

Once you run the above code, the workflows can use app permissions feature programmatically using CSOM.

You may like following SharePoint designer workflow tutorials:

In this tutorial, we learned how to activate workflows can use app permissions feature programmatically using CSOM.

>