Export (0) Print
Expand All

SiteMapNodeCollection Class

Note: This class is new in the .NET Framework version 2.0.

Provides a strongly typed collection for SiteMapNode objects and implements the IHierarchicalEnumerable interface to support navigating through the collection.

Namespace: System.Web
Assembly: System.Web (in system.web.dll)

public class SiteMapNodeCollection : IHierarchicalEnumerable, IList, ICollection, 
	IEnumerable
public class SiteMapNodeCollection implements IHierarchicalEnumerable, IList, 
	ICollection, IEnumerable
public class SiteMapNodeCollection implements IHierarchicalEnumerable, IList, 
	ICollection, IEnumerable

The SiteMapNodeCollection class provides a strongly typed collection for SiteMapNode objects. It stores SiteMapNode objects internally in a zero-based array.

You can modify a SiteMapNodeCollection collection when it is first created, and then use the following methods to add, copy, and remove SiteMapNode objects:

  • To add SiteMapNode objects, use the Add, AddRange, and Insert methods.

  • To copy SiteMapNode objects, use the CopyTo method.

  • To remove SiteMapNode objects, use the Remove method.

You can create a read-only SiteMapNodeCollection, which does not permit adding, copying, nor removing SiteMapNode objects, by using the static ReadOnly method. The SiteMapNodeCollection collections that are returned by the SiteMapNode.GetAllNodes and GetChildren methods are read-only, as is the SiteMapNodeCollection that is returned when the ChildNodes property is accessed on a SiteMapNode object that is returned from a provider. A NotSupportedException exception is thrown, if you attempt to modify a read-only SiteMapNodeCollection by setting the default indexer property or by using any of the following methods:

Use the IsReadOnly property to check the collection before calling any of the methods in the preceding list.

The following code example demonstrates how to create a SiteMapNodeCollection collection, and then add SiteMapNode objects to it using the AddRange method. The SiteMapNodeCollection is a subset of the current site map, showing only the first two hierarchical levels.


// 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>");
}

System.Object
  System.Web.SiteMapNodeCollection

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0

Community Additions

ADD
Show:
© 2014 Microsoft