2

Code looks pretty straightforward but fails with below exception

"The collection was modified. Enumeration operation may not execute."}





  private static void RemoveRecentNodeFromQuickLaunch(ClientContext clientContext, Web newWeb)
        {
            NavigationNodeCollection quickLaunchNodeColl = newWeb.Navigation.QuickLaunch;
            clientContext.Load(quickLaunchNodeColl);
            clientContext.ExecuteQuery();

            //// Display all the node title which is available in the quick launch bar
            foreach (NavigationNode node in quickLaunchNodeColl)
            {
                if(node.Title.Contains("Recent"))
                {
                    node.DeleteObject();
                }
            }
            clientContext.ExecuteQuery();

        }

Any idea how to modify it?

3

Basically you are iterating through a collection and modifying the collection itself, which is not allowed.

Instead or foreach loop ,Change the code to:

    NavigationNode node = quickLaunchNodeColl.Where(n => n.Title.Contains("Recent")).FirstOrDefault();
 node.DeleteObject();

Or use for loop instead of foreach

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.