Tuesday, April 10, 2012

Delete all items from Sharepoint QuickLaunch menu

public static void CleanQuickLaunch(SPWeb web)
{
try
{
SPNavigationNodeCollection nodes = web.Navigation.QuickLaunch;
int nodeCount = nodes.Count;
int iNode = 0;
for (iNode = nodeCount -1; iNode >=0 ; iNode--)
{
try
{
SPNavigationNode node = web.Navigation.QuickLaunch[iNode];
if (node.Children.Count > 0)
{
int nodeChildCount = node.Children.Count;
int iNodeChild = 0;
for (iNodeChild = nodeChildCount - 1; iNodeChild >= 0; iNodeChild--)
{
try
{
Debug.WriteLine(node.Children[iNodeChild].Title);
node.Children[iNodeChild].Delete();
}
catch (Exception ex)
{
Logging.LogException("CleanQuickLaunch Delete Child Node", ex);
}
}
}
node.Delete();
}
catch (Exception ex)
{
Logging.LogException("CleanQuickLaunch Delete Node", ex);
}
}
}
catch (Exception ex)
{
Logging.LogException("CleanQuickLaunch", ex);
}
}

No comments:

Post a Comment