Skip to content

Instantly share code, notes, and snippets.

@AsishP
Last active June 28, 2018 05:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AsishP/b817455ce58b753e4f02ae5a0482e7a4 to your computer and use it in GitHub Desktop.
Save AsishP/b817455ce58b753e4f02ae5a0482e7a4 to your computer and use it in GitHub Desktop.
using (var context = new ClientContext(<siteURL>))
{
contextAsset.Credentials = new SharePointOnlineCredentials(UserName, SecurePass);
Web web = contextAsset.Web;
contextAsset.Load(web, w => w.Navigation);
contextAsset.Load(web);
contextAsset.ExecuteQuery();
//Start working on Navigation
NavigationNodeCollection lefthandNav = web.Navigation.QuickLaunch;
contextAsset.Load(lefthandNav);
List<int> navIds = new List<int>(); // To be used in Deletion
contextAsset.ExecuteQuery();
foreach (NavigationNode nodeLeftHandNav in lefthandNav)
{
contextAsset.Load(nodeLeftHandNav.Children);
contextAsset.ExecuteQuery();
if (nodeLeftHandNav.Children.Count > 0)
{
foreach (NavigationNode nodeLeftHandNavChild1 in nodeLeftHandNav.Children)
{
contextAsset.Load(nodeLeftHandNavChild1.Children);
contextAsset.ExecuteQuery();
if (nodeLeftHandNavChild1.Children.Count > 0)
{
foreach (NavigationNode nodeLefthandNavChild2 in nodeLeftHandNavChild1.Children)
{
<Do something>
//For deletion
if(nodeLefthandNavChild2 == TobeDeleted)
navIds.Add(nodeLeftHandNav.Id);
}
}
else
{
<Do something>
//For deletion
if(nodeLeftHandNavChild1 == TobeDeleted)
navIds.Add(nodeLeftHandNav.Id);
}
}
}
else
{
<Do something>
//For deletion
if(nodeLeftHandNavChild1 == TobeDeleted)
navIds.Add(nodeLeftHandNav.Id);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment