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.

1 Answer 1

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());
}
1
  • Thanks for your help but, I want C# code.
    – Y. Jagtap
    Commented Jun 26, 2017 at 5:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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