Last active
June 12, 2018 15:01
-
-
Save vaderj/d244c9830053cc4607f3610c7fabc1db to your computer and use it in GitHub Desktop.
Enable a Site Collection feature via CSOM #C# SharePoint #SOAP #CSOM
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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