SiteMapNode.Clone Method

Definition

Erstellt einen neuen Knoten, der eine Kopie des aktuellen Knotens darstellt.Creates a new node that is a copy of the current node.

Overloads

Clone()

Erstellt einen neuen Knoten, der eine Kopie des aktuellen Knotens darstellt.Creates a new node that is a copy of the current node.

Clone(Boolean)

Erstellt eine neue Kopie, die eine Kopie des aktuellen Knotens darstellt, wobei optional alle übergeordneten Knoten und Vorgängerknoten des aktuellen Knotens geklont werden.Creates a new copy that is a copy of the current node, optionally cloning all parent and ancestor nodes of the current node.

Clone()

Erstellt einen neuen Knoten, der eine Kopie des aktuellen Knotens darstellt.Creates a new node that is a copy of the current node.

public:
 virtual System::Web::SiteMapNode ^ Clone();
public virtual System.Web.SiteMapNode Clone ();
abstract member Clone : unit -> System.Web.SiteMapNode
override this.Clone : unit -> System.Web.SiteMapNode
Public Overridable Function Clone () As SiteMapNode

Returns

SiteMapNode

Ein neuer Knoten, der eine Kopie des aktuellen Knotens darstellt.A new node that is a copy of the current node.

Remarks

Ruft die Clone Methode auf, wobei der-Parameter auf falsefestgelegt ist.Calls the Clone method with the parameter set to false. Die Eigenschaften Anbieter, Title, Url, Descriptionund Key werden kopiert.The provider, Title, Url, Description, and Key properties are copied. Die Roles-und Attributes Sammlungen werden in neue Sammlungen kopiert.The Roles and Attributes collections are copied to new collections. Vorgänger-und untergeordnete Knoten werden nicht geklont.Ancestor and child nodes are not cloned.

See also

Clone(Boolean)

Erstellt eine neue Kopie, die eine Kopie des aktuellen Knotens darstellt, wobei optional alle übergeordneten Knoten und Vorgängerknoten des aktuellen Knotens geklont werden.Creates a new copy that is a copy of the current node, optionally cloning all parent and ancestor nodes of the current node.

public:
 virtual System::Web::SiteMapNode ^ Clone(bool cloneParentNodes);
public virtual System.Web.SiteMapNode Clone (bool cloneParentNodes);
abstract member Clone : bool -> System.Web.SiteMapNode
override this.Clone : bool -> System.Web.SiteMapNode
Public Overridable Function Clone (cloneParentNodes As Boolean) As SiteMapNode

Parameters

cloneParentNodes
Boolean

true, um alle übergeordneten Knoten und Vorgängerknoten des aktuellen Knotens zu klonen, andernfalls false.true to clone all parent and ancestor nodes of the current node; otherwise, false.

Returns

SiteMapNode

Ein neuer Knoten, der eine Kopie des aktuellen Knotens darstellt.A new node that is a copy of the current node.

Examples

Im folgenden Codebeispiel wird veranschaulicht, wie Sie die Clone-Methode zum Erstellen eines doppelten Site Übersichts Knotens aus dem aktuellen Knoten aufzurufen.The following code example demonstrates how to call the Clone method to create a duplicate site map node from the current node. Die ExpandForumPaths-Methode ist für die Behandlung des SiteMapResolve Ereignisses registriert.The ExpandForumPaths method is registered to handle the SiteMapResolve event. Er verwendet die Clone-Methode, um eine Arbeitskopie des aktuellen Site Übersichts Knotens zu erstellen, Attribute auf der Grundlage von Personalisierungs Daten zu ändern und die Arbeitskopie zurückzugeben.It uses the Clone method to create a working copy of the current site map node, modify attributes based on personalization data, and return the working copy.

private void Page_Load(object sender, EventArgs e)
{
    // The ExpandForumPaths method is called to handle
    // the SiteMapResolve event.
    SiteMap.SiteMapResolve +=
      new SiteMapResolveEventHandler(this.ExpandForumPaths);
}

private SiteMapNode ExpandForumPaths(Object sender, SiteMapResolveEventArgs e)
{
    // The current node represents a Post page in a bulletin board forum.
    // Clone the current node and all of its relevant parents. This
    // returns a site map node that a developer can then
    // walk, modifying each node.Url property in turn.
    // Since the cloned nodes are separate from the underlying
    // site navigation structure, the fixups that are made do not
    // effect the overall site navigation structure.
    SiteMapNode currentNode = SiteMap.CurrentNode.Clone(true);
    SiteMapNode tempNode = currentNode;

    // Obtain the recent IDs.
    int forumGroupID = GetMostRecentForumGroupID();
    int forumID = GetMostRecentForumID(forumGroupID);
    int postID = GetMostRecentPostID(forumID);

    // The current node, and its parents, can be modified to include
    // dynamic querystring information relevant to the currently
    // executing request.
    if (0 != postID)
    {
        tempNode.Url = tempNode.Url + "?PostID=" + postID.ToString();
    }

    if ((null != (tempNode = tempNode.ParentNode)) &&
        (0 != forumID))
    {
        tempNode.Url = tempNode.Url + "?ForumID=" + forumID.ToString();
    }

    if ((null != (tempNode = tempNode.ParentNode)) &&
        (0 != forumGroupID))
    {
        tempNode.Url = tempNode.Url + "?ForumGroupID=" + forumGroupID.ToString();
    }

    return currentNode;
}
Private Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

    ' The ExpandForumPaths method is called to handle
    ' the SiteMapResolve event.
    AddHandler SiteMap.SiteMapResolve, AddressOf Me.ExpandForumPaths

End Sub

Private Function ExpandForumPaths(ByVal sender As Object, ByVal e As SiteMapResolveEventArgs) As SiteMapNode
    ' The current node represents a Post page in a bulletin board forum.
    ' Clone the current node and all of its relevant parents. This
    ' returns a site map node that a developer can then
    ' walk, modifying each node.Url property in turn.
    ' Since the cloned nodes are separate from the underlying
    ' site navigation structure, the fixups that are made do not
    ' effect the overall site navigation structure.
    Dim currentNode As SiteMapNode = SiteMap.CurrentNode.Clone(True)
    Dim tempNode As SiteMapNode = currentNode

    ' Obtain the recent IDs.
    Dim forumGroupID As Integer = GetMostRecentForumGroupID()
    Dim forumID As Integer = GetMostRecentForumID(forumGroupID)
    Dim postID As Integer = GetMostRecentPostID(forumID)

    ' The current node, and its parents, can be modified to include
    ' dynamic querystring information relevant to the currently
    ' executing request.
    If Not (0 = postID) Then
        tempNode.Url = tempNode.Url & "?PostID=" & postID.ToString()
    End If

    tempNode = tempNode.ParentNode
    If Not (0 = forumID) And Not (tempNode Is Nothing) Then
        tempNode.Url = tempNode.Url & "?ForumID=" & forumID.ToString()
    End If

    tempNode = tempNode.ParentNode
    If Not (0 = ForumGroupID) And Not (tempNode Is Nothing) Then
        tempNode.Url = tempNode.Url & "?ForumGroupID=" & forumGroupID.ToString()
    End If

    Return currentNode

End Function

Remarks

Wenn der cloneParentNodes-Parameter trueist, klont die Clone-Methode alle direkten Vorgänger Knoten rekursiv und ordnet Sie dem aktuellen geklonten Knoten zu.If the cloneParentNodes parameter is true, the Clone method recursively clones all direct ancestor nodes and associates them with the current cloned node. Untergeordnete Knoten werden nicht geklont.Child nodes are not cloned.

Die Roles-und Attributes Sammlungen werden auf neue Sammlungen angewendet.The Roles and Attributes collections are applied to new collections.

See also

Applies to