Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I want to access the SP2013 Site Settings-->Master Page/Navigation settings etc using CSOM (client side object model) using JavaScript or REST service or Webservice which I can call from Javascript.

To be more specific:

I want to access and change the Site Setting--> Navigation (under look and Feel)--> Global and Current Navigation to "Structural Navigation" instead of "Managed Navigation". I want to achieve this using CSOM (Javascript / REST/WebSErvice). I dont want to use server side or managed object model.

Can I get the pointer if such API/objects available for SP 2013?

Thanks nks

share|improve this question
add comment

2 Answers

Haven't actually tried, but using ClientContext you should be able to retrieve current Web and set its CustomMasterUrl (http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.client.web.custommasterurl.aspx) using something like

// Starting with ClientContext, the constructor requires a URL to the 
// server running SharePoint. 
ClientContext context = new ClientContext("http://SiteUrl"); 

// The SharePoint web at the URL.
Web web = context.Web; 

web.CustomMasterUrl = "<path_to_master>"; 

// Note that the web.Update() does not trigger a request to the server
// because the client library until ExecuteQuery() is called. 
web.Update(); 

// Execute the query to server.
context.ExecuteQuery(); 
share|improve this answer
    
Thanks Marius, but my requirement is to get and then set the Master Page which are available at that point of time. Would be great if you could give some more pointers!!! thanks nks –  nks Mar 8 '13 at 22:21
    
Sorry, but from your question it doesn't show as such. All master pages are in _catalogs/masterpage library. you only need to get all file with .master extension, e.g. adapt this example msdn.microsoft.com/en-us/library/… –  C. Marius - MVP Mar 8 '13 at 23:00
    
Thanks again Marius...using C# CSOM I can still find the master page. Do you have any idea if we can do it with JavaScript/Jquery OR WebService from API OR REST API?? Happy weekend!!! –  nks Mar 9 '13 at 0:46
    
Yes, you should be able to do the exact same operations –  C. Marius - MVP Mar 9 '13 at 9:33
    
I am able to change the Master Page but as soon as I refresh my Page after this change. I get File not found error on my pages of site. Do you have any idea if we are missing anything here? var web;var masterurl;var site; function sharePointReady() { context = new SP.ClientContext.get_current(); web = context.get_web(); context.load(web, 'ServerRelativeUrl'); web.set_customMasterUrl('/_catalogs/masterpage/seattle.master'); web.update(); context.executeQueryAsync(Function.createDelegate(this, this.onSuccess), Function.createDelegate(this, this.onFail)); } –  nks Mar 12 '13 at 0:04
show 1 more comment

I had received similar 'File Not Found' error while trying to set the master page. Try to set your custom master page as:

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

ctx.load(web, 'ServerRelativeUrl');
web.set_masterUrl('/sites/site_collection/_catalogs/masterpage/your_masterpage.master');
web.update();

ctx.executeQueryAsync(
function() {
    window.console && console.log('Master page successfully set to: ' + web.get_customMasterUrl());
},
function (sender, args) { alert("Error" + args.get_message());
});

Note the site relative path: "/sites/site_collection" which is needed if your site is not at the root level.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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