Skip to content

Instantly share code, notes, and snippets.

@vaderj
Last active June 12, 2018 15:01
Show Gist options
  • Save vaderj/d244c9830053cc4607f3610c7fabc1db to your computer and use it in GitHub Desktop.
Save vaderj/d244c9830053cc4607f3610c7fabc1db to your computer and use it in GitHub Desktop.
Enable a Site Collection feature via CSOM #C# SharePoint #SOAP #CSOM
protected void removeMasterPage(object sender, EventArgs e)
{
var url = "<URL to site>"
using (ClientContext clientContext = new ClientContext(url))
{
Site spsite = clientContext.Site;
FeatureCollection siteFeatures = spsite.Features;
clientContext.Load(siteFeatures);
Guid masterPageFeatureGuid = new Guid("efcd0dac-835c-40ca-af13-c868d6cc13db");
siteFeatures.Remove(masterPageFeatureGuid, true);
clientContext.ExecuteQuery();
clientContext.Dispose();
}
}
protected void applyMasterPage(object sender, EventArgs e)
{
var url = "<URL to site>"
using (ClientContext clientContext = new ClientContext(url))
{
Site spsite = clientContext.Site;
FeatureCollection siteFeatures = spsite.Features;
clientContext.Load(siteFeatures);
Guid masterPageFeatureGuid = new Guid("efcd0dac-835c-40ca-af13-c868d6cc13db");
siteFeatures.Add(masterPageFeatureGuid, false, FeatureDefinitionScope.Farm); // FARM is the required scope for a Site Collection scoped feature. Thnx M$
clientContext.ExecuteQuery();
clientContext.Dispose();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment