0

I was wondering if it would be possible to activate treeview navigation using CSOM? I know it can bedone using powershell (TreeViewEnabled), but that doesn't directly translate to CSOM - at least I can't get it to work.

1

You just need to set the TreeViewEnabled of the CSOM SP Web object.

Try with the below sample code:

// auth code and get web logic

clientContext.Web.TreeViewEnabled = true;
clientContext.Web.Update();
clientContext.ExecuteQuery();

Using JSOM:

SP.SOD.executeFunc('SP.js', 'SP.ClientContext', function(){

    var clientContext = new SP.ClientContext.get_current();
    var web = clientContext.get_web();

    web.set_treeViewEnabled(true);
    web.update()
    clientContext.load(web);
    clientContext.executeQueryAsync(function(){
        console.log("success");
    },function(){
        console.log("error");
    });

});

Using REST API:

var updateTreeView = JSON.stringify(
{  
    '__metadata': {   
         'type': 'SP.Web'   
    },
    'TreeViewEnabled': true
 }); 


$.ajax({
    url: "https://<your-site>/_api/web/",
    type: "POST",
    data: updateTreeView,
    headers: {  
         "accept": "application/json;odata=verbose",  
        "content-type": "application/json;odata=verbose",  
        "X-RequestDigest": $('#__REQUESTDIGEST').val(),    
        "X-HTTP-Method": "MERGE"  
    },  
    success: function (data) {
        console.log("success");
    },
    error: function (err) {
        console.log("error");
    }
});

Reference - CSOM SP Web namespace

  • Hmm it seems I a little out of com comfortzone, would you be able to show me what a javascript function activating treeview would look like? Thanks! – Morten K Sep 7 '18 at 11:09
  • updated answer to use JSOM :) – Gautam Sheth Sep 7 '18 at 11:20
  • Thanks a lot, if the REST api works for this i might use that instead in the workflow which is creating the site in the first place! Can I assume REST api works for disabeling the "normal" quick launch as well? – Morten K Sep 7 '18 at 11:44
  • yes, will work with quick launch as well. – Gautam Sheth Sep 7 '18 at 11:50
  • That's very nice - it's quite odd though that inheriting top navigation isn't supported by REST then. I would expect it to be in the same ballpark, but that doesn't seem to be the case. – Morten K Sep 7 '18 at 11:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.