/// <summary>
        /// Gets the node at level.
        /// </summary>
        /// <param name="startingNode">The starting node.</param>
        /// <param name="level">The level.</param>
        /// <param name="allowForwardSearch">if set to <c>true</c> allow forward search. Forward search will search all parent nodes and child nodes, where in other circumstances only parent nodes are searched.</param>
        /// <returns>The node at level.</returns>
        public static SiteMapNode GetNodeAtLevel(SiteMapNode startingNode, int level, bool allowForwardSearch)
        {
            var startingNodeLevel = startingNode.GetNodeLevel();

            if (startingNodeLevel == level)
            {
                return(startingNode);
            }
            else if (startingNodeLevel > level)
            {
                var node = startingNode;
                while (node != null)
                {
                    if (node.GetNodeLevel() == level)
                    {
                        return(node);
                    }
                    node = node.ParentNode;
                }
            }
            else if (startingNodeLevel < level && allowForwardSearch)
            {
                var node = startingNode;
                while (node != null)
                {
                    if (node.GetNodeLevel() == level)
                    {
                        return(node);
                    }
                    if (node.HasChildNodes)
                    {
                        node = node.ChildNodes[0];
                    }
                    else
                    {
                        break;
                    }
                }
            }

            if (startingNode != null && startingNode.Provider.RootNode != null && allowForwardSearch)
            {
                return(startingNode.Provider.RootNode);
            }

            return(null);
        }
        /// <summary>
        /// Gets the node at level.
        /// </summary>
        /// <param name="startingNode">The starting node.</param>
        /// <param name="level">The level.</param>
        /// <param name="allowForwardSearch">if set to <c>true</c> allow forward search. Forward search will search all parent nodes and child nodes, where in other circumstances only parent nodes are searched.</param>
        /// <returns>The node at level.</returns>
        public static SiteMapNode GetNodeAtLevel(SiteMapNode startingNode, int level, bool allowForwardSearch)
        {
            var startingNodeLevel = startingNode.GetNodeLevel();
            if (startingNodeLevel == level)
            {
                return startingNode;
            }
            else if (startingNodeLevel > level)
            {
                var node = startingNode;
                while (node != null)
                {
                    if (node.GetNodeLevel() == level)
                    {
                        return node;
                    }
                    node = node.ParentNode;
                }
            }
            else if (startingNodeLevel < level && allowForwardSearch)
            {
                var node = startingNode;
                while (node != null)
                {
                    if (node.GetNodeLevel() == level)
                    {
                        return node;
                    }
                    if (node.HasChildNodes)
                    {
                        node = node.ChildNodes[0];
                    }
                    else
                    {
                        break;
                    }
                }
            }

            if (startingNode != null && startingNode.Provider.RootNode != null && allowForwardSearch)
            {
                return startingNode.Provider.RootNode;
            }

            return null;
        }