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


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

Also you can read:

Free SharePoint Migration Tool from Microsoft step by step migration from SharePoint 2016 on premise to SharePoint Online

SharePoint Approved and Rejected buttons not appearing in task form in Visual Studio 2015 workflow

Below is the full code:

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, it will activate the “Workflows can use app permissions” feature.
Hope this will be helpful.

Check out Best Alternative to InfoPath -> Try Now

You May Also like the Following SharePoint Online Tutorials:

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 →