Activate Workflows can use app permissions Feature programmatically using C#.Net .net managed object model code


Here we will discuss how we can activate “Workflows can use app permissions” in SharePoint online site using client object model code (csom). We will use C#.net managed object model code (Microsoft.SharePoint.Client.dll) to activate workflows can use app permissions.


New to Office 365 SharePoint Online? Get Office 365 Enterprise E3 Subscription & Try out all the features

“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.

Activate workflows can use app permissions

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

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;
}
}

You may like following SharePoint designer workflow tutorials:

Once you run the above code, it will activate the “Workflows can use app permissions” feature.
Hope this will be helpful.

Check out Best Alternative to InfoPath -> Try Now

FREE SHAREPOINT 2019 PDF

(Installation & Features)



About Bijay Kumar

I am Bijay from Odisha, India. Currently working in my own venture TSInfo Technologies in Bangalore, India. I am Microsoft Office Servers and Services (SharePoint) MVP (5 times). I works in SharePoint 2016/2013/2010, SharePoint Online Office 365 etc. Check out My MVP Profile.. I also run popular SharePoint web site SharePointSky.com

View all posts by Bijay Kumar →