4
clientContext.Load(web);

NavigationNodeCollection oNavNodeCollection = web.Navigation.QuickLaunch;

NavigationNodeCreationInformation oNewNaviNode = new NavigationNodeCreationInformation();
oNewNaviNode.Title = txtDisplayText.Text;
oNewNaviNode.Url = txtLinkAddress.Text;
oNewNaviNode.AsLastNode = true;


oNavNodeCollection.Add(oNewNaviNode);

clientContext.Load(oNavNodeCollection);
clientContext.ExecuteQuery();

This code executed successfully but no result on Quick Launch Navigation! SharePoint 2013.

2

Please try below code. It works perfectly for me.

var quickLaunchNodeCollection = null;
var oNewNaviNode = null;

function addNavigationNodes() {

    var context = new SP.ClientContext.get_current();

    if (context != undefined && context != null) {

        var web = context.get_web();

        //this.navigationNodeCollection = web.get_navigation().get_topNavigationBar();
        this.quickLaunchNodeCollection = web.get_navigation().get_quickLaunch();

        // Set properties for a new navigation node.
        this.oNewNaviNode = new SP.NavigationNodeCreationInformation();
        oNewNaviNode.set_title("NewNavigationNode");
        oNewNaviNode.set_url("http://www.google.com");

        oNewNaviNode.set_asLastNode(true);
        this.quickLaunchNodeCollection.add(oNewNaviNode);

        context.load(this.quickLaunchNodeCollection);
        context.executeQueryAsync(addNavigationNodesSuccess, addNavigationNodesFailed);
    }
}

function addNavigationNodesSuccess() {
    alert("New node added...");
}

function addNavigationNodesFailed(sender, args) {
    alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
  • Thanks for your help but, I want C# code. – Y. Jagtap Jun 26 '17 at 5:27

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.