In this blog, we’ll learn how to identify whether the tree view is enabled or not in the SharePoint site using REST API
Syntax
REST API Endpoint:
REST API endpoint to use in Add_ins:
<appweburl>/_api/SP.AppContextSite(@target)/web?$select= TreeViewEnabled&@target=<hostweburl>
<appweburl>/_api/SP.AppContextSite(@target)/web?$select= TreeViewEnabled&@target=<hostweburl>
Embed Code Snippet:
The following code snippet can be embed in SharePoint page or in content editor web part as a script. This example is used to check whether the tree view is enabled for the SharePoint website.
- <script type="text/javascript" src="/SiteAssets/Scripts/jquery.min.js"></script>
- <script type="text/javascript">
- $.ajax({
- url: _spPageContextInfo.webAbsoluteUrl+"/_api/web?$select=treeviewenabled", //THE ENDPOINT
- method: "GET",
- headers: { "Accept": "application/json; odata=verbose" },
- success: function (data) {
- //RESULTS HERE!!
- console.log(data.d.TreeViewEnabled)
- if(data.d.TreeViewEnabled)
- alert('Tree view enabled on this site.');
- else
- alert('Tree view disabled on this site.');
- }
- });
- </script>
Add-in Code Snippet
The following code snippet is used in SharePoint Add-in to get the tree view enabled property of a SharePoint web.
The following code snippet is used in SharePoint Add-in to get the tree view enabled property of a SharePoint web.
- // Load the js files and continue to the successHandler
- $.getScript(scriptbase + "SP.RequestExecutor.js", execCrossDomainRequest);
- // Function to prepare and issue the request to get
- // SharePoint data
- function execCrossDomainRequest() {
- // Initialize the RequestExecutor with the add-in web URL.
- var executor = new SP.RequestExecutor(appweburl);
- // Issue the call against the add-in web.
- // To get the TreeViewEnabled property using REST we can hit the endpoint:
- // appweburl/_api/web?select=TreeViewEnabled&@target=hostweburl
- // The response formats the data in the JSON format.
- executor.executeAsync(
- {
- url: appweburl + "/_api/SP.AppContextSite(@target)/web?$select=TreeViewEnabled&@target='" + hostweburl + "'",
- method: "GET",
- headers: {
- "Accept": "application/json; odata=verbose"
- },
- success: successHandler,
- error: errorHandler
- }
- );
- }
- // Function to handle the success event.
- function successHandler(data) {
- var jsonObject = JSON.parse(data.body)
- //jsonObject.d.TreeViewEnabled returns true if enabled otherwise it returns false
- console.log('Tree view enabled on this site: ' + jsonObject.d.TreeViewEnabled);
- if(jsonObject.d.TreeViewEnabled)
- $('#message').html(‘Tree view enabled on this site.');
- else
- $('#message').html(‘Tree view disabled on this site.');
- }
- function errorHandler(data, errorCode, errorMessage) {
- console.log("Could not complete cross-domain call: " + errorMessage);
- }

Join the conversation! Your thoughts help the community grow.