Change SiteMapNode URL Programtically

Locked Change SiteMapNode URL Programtically

  • mercredi 16 mai 2012 17:14
     
      A du code

    Hi I need to change the URL of each node in the site map to add in additional information that each page needs.

    I have tried the code on MSDN it works for the previos level but not for any level proir to that.

    Does anyone have any experience with this?

    AddHandler SiteMap.SiteMapResolve, AddressOf Me.ExpandForumPaths

     

     Private Function ExpandForumPaths(ByVal sender As Object, ByVal e As SiteMapResolveEventArgs) As SiteMapNode
            Try
                Dim currentNode As SiteMapNode = SiteMap.CurrentNode.Clone(True)
                Dim tempNode As SiteMapNode = currentNode
                Dim requestItems As String
                requestItems = Request.RawUrl
                requestItems = requestItems.Substring(requestItems.IndexOf("&"), requestItems.Length - requestItems.IndexOf("&"))
    
    
                tempNode = tempNode.ParentNode
                tempNode.Url = tempNode.Url & "?UI=" & RequestorUI.ToString() & requestItems
    
                Return (currentNode)
            Catch ex As Exception
                Return Nothing
            End Try
        End Function

    Well I found a way to do it.

        Private Sub UpdateMenu()
            Dim CurrentNodeURL As String = ""
            'Dim NodeReadOnlyProperty As Boolean
            Dim requestItems As String
            requestItems = Request.RawUrl
            If requestItems.Contains("&") Then
                requestItems = requestItems.Substring(requestItems.IndexOf("&"), requestItems.Length - requestItems.IndexOf("&"))
            Else
                requestItems = ""
            End If
    
            Dim CurrentNode As SiteMapNode = sitemap.CurrentNode
    
            Do
                CurrentNode.ReadOnly = False
                If Not IsNothing(CurrentNode.ParentNode) Then
                    CurrentNode.Url = CurrentNode.Url & "?UI=" & RequestorUI.ToString() & requestItems
                Else
                    CurrentNode.Url = CurrentNode.Url & "?UI=" & RequestorUI.ToString() & requestItems
                    Exit Do
                End If
                CurrentNode = CurrentNode.ParentNode
            Loop
            Dim mysitemap As SiteMapPath = CType(CType(Master.FindControl("Header"), ContentPlaceHolder).FindControl("SiteMapPath1"), SiteMapPath)
            mysitemap.DataBind()
        End Sub

    • Modifié BAZARI mercredi 16 mai 2012 17:55
    •  

Toutes les réponses

  • jeudi 17 mai 2012 05:42
    Modérateur
     
     

    Hi BAZARI,

    >>Well I found a way to do it.

    Thanks for sharing the solution here. Please keep the original post and add your solution as reply next time. It will be easier for members who have similar issue to search for the solution.

    Good day!


    Mark Liu-lxf [MSFT]
    MSDN Community Support | Feedback to us