Friday, August 15, 2014

SharePoint 2013 - Activate Feature using Client Object Model

You can activate the Site Collection Features / Site Feature using Client Object Model (CSOM) . All you need to do is to put the below code in the script editor or Content Editor Webpart in you page.

 <script src="https://Servername/Shared%20Documents/jquery-1.8.3.min.js" type="text/javascript"></script>

<script type="text/javascript">
var context = SP.ClientContext.get_current();
$(document).ready(function () {
var site = context.get_site();
context.load(site);
context.executeQueryAsync(function () {
site.get_features().add("Enter Feature ID Here", true, 0);
context.executeQueryAsync(Sucess() {
function("Sucess!");
},
function(sender, args){
alert("Error : " + args );
});
},
function (sender, args) {
alert("Oops. Sorry! " + args);
});
});
</script>

 

Happy Browsing!
Relax..