SiteMapNodeCollection Constructors

Definition

Initializes a new instance of the SiteMapNodeCollection class.

Overloads

SiteMapNodeCollection()

Initializes a new instance of the SiteMapNodeCollection class, which is the default instance.

SiteMapNodeCollection(Int32)

Initializes a new instance of the SiteMapNodeCollection class with the specified initial capacity.

SiteMapNodeCollection(SiteMapNode)

Initializes a new instance of the SiteMapNodeCollection class and adds the SiteMapNode object to the InnerList property for the collection.

SiteMapNodeCollection(SiteMapNode[])

Initializes a new instance of the SiteMapNodeCollection class and adds the array of type SiteMapNode to the InnerList property for the collection.

SiteMapNodeCollection(SiteMapNodeCollection)

Initializes a new instance of the SiteMapNodeCollection class and adds all the list items of the specified SiteMapNodeCollection collection to the InnerList property for the collection.

SiteMapNodeCollection()

Initializes a new instance of the SiteMapNodeCollection class, which is the default instance.

C#
public SiteMapNodeCollection();

Examples

The following code example demonstrates how to use the SiteMapNodeCollection constructor to create a new SiteMapNodeCollection collection, and then add elements to the SiteMapNodeCollection with the Add method.

C#
// The LoadSiteMapData() method loads site navigation
// data from persistent storage into a DataTable.
DataTable siteMap = LoadSiteMapData();

// Create a SiteMapNodeCollection.
SiteMapNodeCollection nodes = new SiteMapNodeCollection();

// Create a SiteMapNode and add it to the collection.
SiteMapNode tempNode;
DataRow row;
int index = 0;

while (index < siteMap.Rows.Count)
{

    row = siteMap.Rows[index];

    // Create a node based on the data in the DataRow.
    tempNode = new SiteMapNode(SiteMap.Provider,
                                row["Key"].ToString(),
                                row["Url"].ToString());

    // Add the node to the collection.
    nodes.Add(tempNode);
    ++index;
}

Remarks

Use the SiteMapNodeCollection constructor to create an empty SiteMapNodeCollection collection. You can add elements to the SiteMapNodeCollection using the Add, AddRange, or Insert method.

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

SiteMapNodeCollection(Int32)

Initializes a new instance of the SiteMapNodeCollection class with the specified initial capacity.

C#
public SiteMapNodeCollection(int capacity);

Parameters

capacity
Int32

The initial capacity of the SiteMapNodeCollection.

Remarks

Use the SiteMapNodeCollection constructor to create a SiteMapNodeCollection collection with the specified initial capacity.

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

SiteMapNodeCollection(SiteMapNode)

Initializes a new instance of the SiteMapNodeCollection class and adds the SiteMapNode object to the InnerList property for the collection.

C#
public SiteMapNodeCollection(System.Web.SiteMapNode value);

Parameters

Exceptions

value is null.

Examples

The following code example demonstrates how to create a SiteMapNodeCollection collection with a single initial SiteMapNode object, and then add a SiteMapNodeCollection of SiteMapNode objects to it using the AddRange method. You can modify the SiteMapNodeCollection, even though the individual SiteMapNode objects might be read-only.

C#

// Create a SiteMapNodeCollection with all the nodes
// from the first two hierarchical levels of the current
// site map.
SiteMapNodeCollection baseCollection =
    new SiteMapNodeCollection(SiteMap.RootNode);

SiteMapNodeCollection childCollection =
    SiteMap.RootNode.ChildNodes;

baseCollection.AddRange(childCollection);

Response.Write( "<BR>Derived SiteMapNodeCollection.<BR><HR><BR>");
foreach (SiteMapNode node in baseCollection) {
    Response.Write( node.Title + "<BR>");
}

Remarks

Use the SiteMapNodeCollection constructor to create a SiteMapNodeCollection collection with a single initial SiteMapNode object. You can add elements to the SiteMapNodeCollection using the Add, AddRange, or Insert method.

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

SiteMapNodeCollection(SiteMapNode[])

Initializes a new instance of the SiteMapNodeCollection class and adds the array of type SiteMapNode to the InnerList property for the collection.

C#
public SiteMapNodeCollection(System.Web.SiteMapNode[] value);

Parameters

value
SiteMapNode[]

An array of type SiteMapNode to add to the SiteMapNodeCollection.

Exceptions

value is null.

Remarks

Using the SiteMapNodeCollection constructor is equivalent to calling the SiteMapNodeCollection constructor and adding elements to the SiteMapNodeCollection collection with the AddRange method.

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

SiteMapNodeCollection(SiteMapNodeCollection)

Initializes a new instance of the SiteMapNodeCollection class and adds all the list items of the specified SiteMapNodeCollection collection to the InnerList property for the collection.

C#
public SiteMapNodeCollection(System.Web.SiteMapNodeCollection value);

Parameters

value
SiteMapNodeCollection

A SiteMapNodeCollection that contains the SiteMapNode to add to the current SiteMapNodeCollection.

Exceptions

value is null.

Examples

The following code example demonstrates how to create a SiteMapNodeCollection collection using another SiteMapNodeCollection of SiteMapNode objects as a base. The SiteMapNode.GetAllNodes method returns a read-only SiteMapNodeCollection, which is detected when the IsReadOnly property returns true. A new SiteMapNodeCollection is created using the read-only SiteMapNodeCollection and the Add and Remove methods can be called successfully.

C#
SiteMapNodeCollection siteNodes = SiteMap.RootNode.GetAllNodes();

if ( siteNodes.IsReadOnly ||
     siteNodes.IsFixedSize )
{
    Response.Write("Collection is read-only or has fixed size.<BR>");

    // Create a new, modifiable collection from the existing one.
    SiteMapNodeCollection modifiableCollection =
         new SiteMapNodeCollection(siteNodes);

    // The MoveNode example method moves a node from position one to
    // the last position in the collection.
    MoveNode(modifiableCollection);
}
else {
    MoveNode(siteNodes);
}

Remarks

Using the SiteMapNodeCollection constructor is equivalent to calling the SiteMapNodeCollection constructor and adding elements to the SiteMapNodeCollection collection with the AddRange method.

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