Focus on Microsoft Technologies - Tutorials, Articles, Code Samples.

Monday, September 04, 2006

Get Page Title Based On Site Navigation in .NET

 Private Function GetPageTitleBasedOnSiteNavigation() As String
        If SiteMap.CurrentNode Is Nothing Then
            Throw New ArgumentException("currentNode cannot be Nothing")
        End If

        'We are visiting a page defined in the site map - build up the
        'page title based on the site map node's place in the hierarchy

        Dim output As String = String.Empty
        Dim currentNode As SiteMapNode = SiteMap.CurrentNode

        While currentNode IsNot Nothing
            If output.Length > 0 Then
                output = currentNode.Title & " :: " & output
                output = currentNode.Title
            End If

            currentNode = currentNode.ParentNode
        End While

        Return output
End Sub

Post a Comment