In this blog, we have discussed about adding, retrieving, and deleting the SharePoint online quick launch navigation menu using the c# server Object model. Follow the below coding to get the result.
- Add new term in quick launch:
Add the below code in your Program.cs.
namespace GetNavigationNode
{
class Program
{
static void Main(string[] args)
{
string userName = “user1@tenantname.onmicrosoft.com”;
string password = “********”;
string siteUrl = “https:// tenantname.sharepoint.com/sites/AssociateSite”;
SecureString securePassword = new SecureString();
foreach (char c in password)
{
securePassword.AppendChar(c);
}
var credentials = new SharePointOnlineCredentials(userName, securePassword);
using (ClientContext clientContext = new ClientContext(siteUrl))
{
clientContext.Credentials = credentials;
NavigationNodeCollection qlNavNodeColl = clientContext.Web.Navigation.QuickLaunch;
clientContext.Load(clientContext.Web);
clientContext.Load(qlNavNodeColl);
clientContext.ExecuteQuery();
NavigationNodeCreationInformation newNode = new NavigationNodeCreationInformation();
newNode.Title = “Search”;
newNode.Url = “https://www.google.com”;
qlNavNodeColl.Add(newNode);
clientContext.ExecuteQuery();
}
}
}
}
After running the code:
![](https://softreetechnology.com/wp-content/uploads/2021/04/Bis.1-1.png)
2. Get Navigation Node:
Add the below code to get all the term from quicklunch.
using (ClientContext clientContext = new ClientContext(siteUrl))
{
clientContext.Credentials = credentials;
NavigationNodeCollection qlNavNodeColl = clientContext.Web.Navigation.QuickLaunch;
clientContext.Load(clientContext.Web);
clientContext.Load(qlNavNodeColl);
clientContext.ExecuteQuery();
foreach (NavigationNode navToDelete in qlNavNodeColl) {
var navNodeTitle = navToDelete.Title;
Console.WriteLine(“Navigation Node is : ” + navNodeTitle);
}
}
![](https://softreetechnology.com/wp-content/uploads/2021/04/Bis.2-1.png)
3. Delete Navigation Node:
Add below code to remove the quick launch term
string userName = “user1@tenantname.onmicrosoft.com”;
string password = “********”;
string siteUrl = “https:// tenantname.sharepoint.com/sites/AssociateSite”;
SecureString securePassword = new SecureString();
foreach (char c in password)
{
securePassword.AppendChar(c);
}
var credentials = new SharePointOnlineCredentials(userName, securePassword);
using (ClientContext clientContext = new ClientContext(siteUrl))
{
clientContext.Credentials = credentials;
NavigationNodeCollection qlNavNodeColl = clientContext.Web.Navigation.QuickLaunch;
clientContext.Load(clientContext.Web);
clientContext.Load(qlNavNodeColl);
clientContext.ExecuteQuery();
foreach (NavigationNode navToDelete in qlNavNodeColl) {
var title = navToDelete.Title;
if (title == “Search”) {
navToDelete.DeleteObject();
clientContext.ExecuteQuery();
}
}
}
}
After running the code:
![](https://softreetechnology.com/wp-content/uploads/2021/04/Bis3-1.png)
Conclusion:
From the above example of the code, we can conclude that, the CRUD operation of a quick launch navigation node in SharePoint Online using c# is very effective as it reduces the amount of time. You can also use this code for SharePoint 2019,2016.
Key Words:
- Add, Get and Delete Quick Launch Navigation using c#
- CRUD operation of Quick Launch using c#
- Programmatically add ,remove and get navigation node using c#(Sever Object Model)