How to Add Quick Launch As a Child in SharePoint Office 365 Programmatically using CSOM C#

Sathish Nadarajan
 
Solution Architect
January 29, 2017
 
Rate this article
 
Views
3746

In this article, we will be seeing how to Add Quick Launch as a Child in SharePoint Office 365 Programmatically using CSOM C#

 namespace Console.Office365
 {
     using Microsoft.SharePoint.Client;
     using Microsoft.SharePoint.Client.Taxonomy;
     using Newtonsoft.Json.Linq;
     using System;
     using System.Collections.Generic;
     using System.IO;
     using System.Linq;
     using System.Threading.Tasks;
 
     class Program
     {
         static void Main(string[] args)
         {
             AddQuickLaunchAsChild();
         }
 
         public static void AddQuickLaunchAsChild()
         {
             OfficeDevPnP.Core.AuthenticationManager authMgr = new OfficeDevPnP.Core.AuthenticationManager();
 
             string siteUrl = "https://****.sharepoint.com/sites/communitysite/";
             string userName = "Sathish@******.onmicrosoft.com";
             string password = "************";
 
             using (var ctx = authMgr.GetSharePointOnlineAuthenticatedContextTenant(siteUrl, userName, password))
             {
                 Web web = ctx.Web;
                 ctx.Load(web);
 
                 NavigationNodeCollection quickLaunchCollection = web.Navigation.QuickLaunch;
                 ctx.Load(quickLaunchCollection);
                 ctx.ExecuteQueryRetry();
 
                 NavigationNode parentNode = quickLaunchCollection.Where(n => n.Title == "Heading3").FirstOrDefault();
 
                 NavigationNodeCreationInformation nodeCreationInformation = new NavigationNodeCreationInformation();
 
                 nodeCreationInformation.Title = "Heading3.1";
                 nodeCreationInformation.Url = "https://google.com";
 
                 parentNode.Children.Add(nodeCreationInformation);
                 parentNode.Update();
 
                 ctx.ExecuteQueryRetry();
             }
         }
     }
 }
 
 

Happy Coding,

Sathish Nadarajan.

Author Info

Sathish Nadarajan
 
Solution Architect
 
Rate this article
 
Sathish is a Microsoft MVP for SharePoint (Office Servers and Services) having 15+ years of experience in Microsoft Technologies. He holds a Masters Degree in Computer Aided Design and Business ...read more
 

Leave a comment