SiteMapNode.Clone Method

Definition

Creates a new node that is a copy of the current node.

Overloads

Clone()

Creates a new node that is a copy of the current node.

Clone(Boolean)

Creates a new copy that is a copy of the current node, optionally cloning all parent and ancestor nodes of the current node.

Clone()

Creates a new node that is a copy of the current node.

public virtual System.Web.SiteMapNode Clone();

Returns

A new node that is a copy of the current node.

Remarks

Calls the Clone method with the parameter set to false. The provider, Title, Url, Description, and Key properties are copied. The Roles and Attributes collections are copied to new collections. Ancestor and child nodes are not cloned.

See also

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

Clone(Boolean)

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);

Parameters

cloneParentNodes
Boolean

true to clone all parent and ancestor nodes of the current node; otherwise, false.

Returns

A new node that is a copy of the current node.

Examples

The following code example demonstrates how to call the Clone method to create a duplicate site map node from the current node. The ExpandForumPaths method is registered to handle the SiteMapResolve event. 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;
}

Remarks

If the cloneParentNodes parameter is true, the Clone method recursively clones all direct ancestor nodes and associates them with the current cloned node. Child nodes are not cloned.

The Roles and Attributes collections are applied to new collections.

See also

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1