This documentation is archived and is not being maintained.

SiteMapNodeCollection.ReadOnly Method

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

Returns a read-only collection that contains the nodes in the specified SiteMapNodeCollection collection.

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

public static SiteMapNodeCollection ReadOnly (
	SiteMapNodeCollection collection
)
public static SiteMapNodeCollection ReadOnly (
	SiteMapNodeCollection collection
)
public static function ReadOnly (
	collection : SiteMapNodeCollection
) : SiteMapNodeCollection

Parameters

collection

The SiteMapNodeCollection that contains the SiteMapNode objects to add to the read-only SiteMapNodeCollection.

Return Value

A read-only SiteMapNodeCollection with the same SiteMapNode elements and structure as the original SiteMapNodeCollection.

Exception typeCondition

ArgumentNullException

collection is a null reference (Nothing in Visual Basic).

You can test whether a SiteMapNodeCollection collection is read-only by checking the IsReadOnly property. The IsFixedSize property also returns true when a SiteMapNodeCollection is read-only.

Notes to Implementers A read-only SiteMapNodeCollection collection supports read and search operations, but does not support the Add, AddRange, Clear, Insert, Remove, and RemoveAt methods, nor the setter on the default indexer property, Item.

The following code example demonstrates how to use the IsReadOnly property to test whether a SiteMapNodeCollection collection is read-only or modifiable. If siteNodes is modifiable, MoveNode is called on it; otherwise, a clone SiteMapNodeCollection is created, using siteNodes as a base.

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


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
Show: