SiteMapNode クラス

定義

SiteMap クラスと、SiteMapProvider 抽象クラスを実装するクラスによって記述される階層サイト マップ構造に存在するノードを表します。

public ref class SiteMapNode : ICloneable, System::Web::UI::IHierarchyData, System::Web::UI::INavigateUIData
public class SiteMapNode : ICloneable, System.Web.UI.IHierarchyData, System.Web.UI.INavigateUIData
type SiteMapNode = class
    interface ICloneable
    interface IHierarchyData
    interface INavigateUIData
Public Class SiteMapNode
Implements ICloneable, IHierarchyData, INavigateUIData
継承
SiteMapNode
実装

このセクションには、2 つのコード例が含まれています。 最初のコード例では、新しいサイト マップ ノード コレクションを作成し、それに要素を追加する方法を示します。 2 番目のコード例では、テキスト ファイルからサイト マップ データを読み込む方法を示します。

次のコード例では、 コンストラクターを SiteMapNodeCollection 使用して新しい SiteMapNodeCollection コレクションを作成し、 メソッドを使用して要素を追加する方法を Add 示します。

// 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;
}
' The LoadSiteMapData() Function loads site navigation
' data from persistent storage into a DataTable.

Dim siteMapData As DataTable
siteMapData = LoadSiteMapData()

' Create a SiteMapNodeCollection.
Dim nodes As New SiteMapNodeCollection()

' Create a SiteMapNode and add it to the collection.
Dim tempNode As SiteMapNode
Dim row As DataRow
Dim index As Integer
index = 0

While (index < siteMapData.Rows.Count)

    row = siteMapData.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 = index + 1
End While

次のコード例は、 が SimpleTextSiteMapProvider コンマ区切りの文字列にサイト マップ データを含むテキスト ファイルを解析する方法を示しています。 ファイルから読み取られた行ごとに、 クラスの内部追跡コレクションに新しい SiteMapNode オブジェクトが追加されます。

このコード例は、SiteMapProvider クラスのために提供されている大規模な例の一部です。

protected virtual void LoadSiteMapFromStore()
{
  string pathToOpen;

  lock (this)
  {
    // If a root node exists, LoadSiteMapFromStore has already
    // been called, and the method can return.
    if (rootNode != null)
    {
      return;
    }
    else
    {
      pathToOpen = HttpContext.Current.Server.MapPath("~" + "\\" + sourceFilename);

      if (File.Exists(pathToOpen))
      {
        // Open the file to read from.
        using (StreamReader sr = File.OpenText(pathToOpen))
        {

          // Clear the state of the collections and rootNode
          rootNode = null;
          siteMapNodes.Clear();
          childParentRelationship.Clear();

          // Parse the file and build the site map
          string s = "";
          string[] nodeValues = null;
          SiteMapNode temp = null;

          while ((s = sr.ReadLine()) != null)
          {

            // Build the various SiteMapNode objects and add
            // them to the ArrayList collections. The format used
            // is: URL,TITLE,DESCRIPTION,PARENTURL

            nodeValues = s.Split(',');

            temp = new SiteMapNode(this,
                HttpRuntime.AppDomainAppVirtualPath + "/" + nodeValues[0],
                HttpRuntime.AppDomainAppVirtualPath + "/" + nodeValues[0],
                nodeValues[1],
                nodeValues[2]);

            // Is this a root node yet?
            if (null == rootNode &&
                string.IsNullOrEmpty(nodeValues[3]))
            {
              rootNode = temp;
            }

          // If not the root node, add the node to the various collections.
            else
            {
              siteMapNodes.Add(new DictionaryEntry(temp.Url, temp));
              // The parent node has already been added to the collection.
              SiteMapNode parentNode =
                       FindSiteMapNode(HttpRuntime.AppDomainAppVirtualPath + "/" + nodeValues[3]);
              if (parentNode != null)
              {
                childParentRelationship.Add(new DictionaryEntry(temp.Url, parentNode));
              }
              else
              {
                throw new Exception("Parent node not found for current node.");
              }
            }
          }
        }
      }
      else
      {
        throw new Exception("File not found");
      }
    }
  }
  return;
}
  Protected Overridable Sub LoadSiteMapFromStore()
    Dim pathToOpen As String
    SyncLock Me
      ' If a root node exists, LoadSiteMapFromStore has already
      ' been called, and the method can return.
      If Not (aRootNode Is Nothing) Then
        Return
      Else
        pathToOpen = HttpContext.Current.Server.MapPath("~" & "\\" & sourceFilename)
        If File.Exists(pathToOpen) Then
          ' Open the file to read from.
          Dim sr As StreamReader = File.OpenText(pathToOpen)
          Try

            ' Clear the state of the collections and aRootNode
            aRootNode = Nothing
            siteMapNodes.Clear()
            childParentRelationship.Clear()

            ' Parse the file and build the site map
            Dim s As String = ""
            Dim nodeValues As String() = Nothing
            Dim temp As SiteMapNode = Nothing

            Do
              s = sr.ReadLine()

              If Not s Is Nothing Then
                ' Build the various SiteMapNode objects and add
                ' them to the ArrayList collections. The format used
                ' is: URL,TITLE,DESCRIPTION,PARENTURL
                nodeValues = s.Split(","c)

                temp = New SiteMapNode(Me, _
                    HttpRuntime.AppDomainAppVirtualPath & "/" & nodeValues(0), _
                    HttpRuntime.AppDomainAppVirtualPath & "/" & nodeValues(0), _
                    nodeValues(1), _
                    nodeValues(2))

                ' Is this a root node yet?
                If aRootNode Is Nothing AndAlso _
                  (nodeValues(3) Is Nothing OrElse _
                   nodeValues(3) = String.Empty) Then
                  aRootNode = temp

                  ' If not the root node, add the node to the various collections.
                Else

                  siteMapNodes.Add(New DictionaryEntry(temp.Url, temp))

                  ' The parent node has already been added to the collection.
                  Dim parentNode As SiteMapNode = _
                      FindSiteMapNode(HttpRuntime.AppDomainAppVirtualPath & "/" & nodeValues(3))

                  If Not (parentNode Is Nothing) Then
                    childParentRelationship.Add(New DictionaryEntry(temp.Url, parentNode))
                  Else
                    Throw New Exception("Parent node not found for current node.")
                  End If
                End If
              End If
            Loop Until s Is Nothing
          Finally
            sr.Close()
          End Try
        Else
          Throw New Exception("File not found")
        End If
      End If
    End SyncLock
    Return
  End Sub
End Class

注釈

オブジェクトは SiteMapNode 、サイト マップ構造の Web サイト ページを表します。 SiteMapNode オブジェクトは、1 つ以上のサイト マップ プロバイダーを使用して、永続的ストレージからメモリにサイト マップ データを読み込む際に、実行時に静的 SiteMap クラスによって読み込まれます。 SiteMapNodeオブジェクトは、 コントロールなどの SiteMapPath Web サーバー コントロールで使用するために、 クラスによってSiteMapNodeItemラップされます。

SiteMapNodeクラスには、Web サイト内の 1 つのページを記述するために使用されるいくつかのプロパティが含まれます。これには、ページを記述するプロパティ (、、 プロパティなどUrlTitleDescription) が含まれます。 プロパティは、ASP.NET の既定のサイト マップ プロバイダーである クラスによってXmlSiteMapProvider使用されますが、プロバイダーがノードの追跡に使用する内部コレクションの参照キーとして使用されますがUrlSiteMapNodeこのクラスは、サイト マップ プロバイダーがノードを追跡するために使用できる基本的なKeyプロパティをサポートしています。 さらに、 Url プロパティは、ナビゲーション構造内のページへのハイパーリンクをレンダリングするために、ナビゲーション コントロールによって使用されます。 プロパティは Title 、 の SiteMapNodeフレンドリ名であり、多くの場合、Web フォームの HTML タイトルと同じであり、ナビゲーション コントロールによって単純なラベルをレンダリングするために使用されます。 最後に、オブジェクトを NameValueCollection 使用するサイト マップ プロバイダーは、追加 Attributes の属性のコレクションを使用 SiteMapNode できますが、基底 SiteMapNode クラスでは使用できない追加のプロパティが必要です。

コンストラクター

SiteMapNode(SiteMapProvider, String)

ノードが示すページを識別する指定された key と、ノードを管理するサイト マップ プロバイダーを使用して、SiteMapNode クラスの新しいインスタンスを初期化します。

SiteMapNode(SiteMapProvider, String, String)

指定された URL、ノードが示すページを識別する key、およびノードを管理するサイト マップ プロバイダーを使用して、SiteMapNode クラスの新しいインスタンスを初期化します。

SiteMapNode(SiteMapProvider, String, String, String)

指定された URL、ノードが示すページを識別する key、タイトル、およびノードを管理するサイト マップ プロバイダーを使用して、SiteMapNode クラスの新しいインスタンスを初期化します。

SiteMapNode(SiteMapProvider, String, String, String, String)

指定された URL、ノードが示すページを識別する key、タイトル、およびノードを管理するサイト マップ プロバイダーを使用して、SiteMapNode クラスの新しいインスタンスを初期化します。

SiteMapNode(SiteMapProvider, String, String, String, String, IList, NameValueCollection, NameValueCollection, String)

ノードを管理する指定されたサイト マップ プロバイダー、URL、タイトル、説明、ロール、追加属性、およびローカライズに使用する明示的なリソース キーと暗黙のリソース キーを使用して、SiteMapNode クラスの新しいインスタンスを初期化します。

プロパティ

Attributes

SiteMapNode クラスに定義されている厳密に型指定されたプロパティ以外の追加属性のコレクションを取得または設定します。

ChildNodes

関連付けられている SiteMapProvider プロバイダーの現在の SiteMapNode オブジェクトのすべての子ノードを取得または設定します。

Description

SiteMapNode の説明を取得します。値の設定も可能です。

HasChildNodes

現在の SiteMapNode に子ノードがあるかどうかを示す値を取得します。

Item[String]

指定したキーに基づいて、Attributes コレクションのカスタム属性、またはリソース文字列を取得または設定します。

Key

サイト マップ ノードのルックアップ キーを表す文字列を取得します。

NextSibling

現在のノードと同じ階層レベルにある次の SiteMapNode ノードを取得します。これは、ParentNode プロパティが存在する場合は、それに相対するものです。

ParentNode

現在のノードの親である SiteMapNode オブジェクトを取得または設定します。

PreviousSibling

現在のノードと同じレベルにある前の SiteMapNode オブジェクトを取得します。これは、ParentNode オブジェクトが存在する場合は、それに相対するものです。

Provider

SiteMapNode オブジェクトを追跡する SiteMapProvider プロバイダーを取得します。

ReadOnly

サイト マップ ノードを変更できるかどうかを示す値を取得または設定します。

ResourceKey

SiteMapNode のローカライズに使用するリソース キーを取得または設定します。

Roles

セキュリティによるトリミング中に使用される SiteMapNode オブジェクトに関連付けられているロールのコレクションを取得または設定します。

RootNode

サイト マップ プロバイダー階層のルート プロバイダーのルート ノードを取得します。 プロバイダー階層が存在しない場合、RootNode プロパティは現在のプロバイダーのルート ノードを取得します。

Title

SiteMapNode オブジェクトのタイトルを取得または設定します。

Url

SiteMapNode オブジェクトが表すページの URL を取得または設定します。

メソッド

Clone()

現在のノードのコピーである新しいノードを作成します。

Clone(Boolean)

現在のノードのコピーである新しいノードを作成します。オプションで、現在のノードのすべての親ノードと先祖ノードを複製できます。

Equals(Object)

現在の SiteMapNode が指定したオブジェクトと同一かどうかを示す値を取得します。

GetAllNodes()

呼び出し元ノードの子孫であるすべての SiteMapNode オブジェクトの読み取り専用コレクションを、分離度に関係なく取得します。

GetDataSourceView(SiteMapDataSource, String)

現在のノードに関連付けられている SiteMapDataSourceView オブジェクトを取得します。

GetExplicitResourceString(String, String, Boolean)

ローカライズする SiteMapNode 属性、リソースが見つからない場合に返す既定の文字列、およびリソースが見つからない場合に例外をスローするかどうかを示すブール値に基づいて、ローカライズされた文字列を取得します。

GetHashCode()

SiteMapNode オブジェクトのハッシュ コードを返します。

GetHierarchicalDataSourceView()

現在のノードに関連付けられている SiteMapHierarchicalDataSourceView オブジェクトを取得します。

GetImplicitResourceString(String)

属性名と、SiteMapNode の追跡に使用する SiteMapProvider で指定されている ResourceKey プロパティに基づいて、ローカライズされた文字列を取得します。

GetType()

現在のインスタンスの Type を取得します。

(継承元 Object)
IsAccessibleToUser(HttpContext)

指定したサイト マップ ノードを指定したコンテキストでユーザーが表示できるかどうかを示す値を取得します。

IsDescendantOf(SiteMapNode)

現在のサイト マップ ノードが、指定したノードの子または直接の子孫であるかどうかを示す値を取得します。

MemberwiseClone()

現在の Object の簡易コピーを作成します。

(継承元 Object)
ToString()

SiteMapNode クラスのインスタンスの値を、それに相当する文字列形式に変換します。

明示的なインターフェイスの実装

ICloneable.Clone()

現在のノードのコピーである新しいノードを作成します。 このメンバーの詳細については、「Clone()」をご覧ください。

IHierarchyData.GetChildren()

現在の項目の階層の子のデータ項目を取得します。 このメンバーの詳細については、「GetChildren()」をご覧ください。

IHierarchyData.GetParent()

現在の項目の階層の親を取得します。 このメンバーの詳細については、「GetParent()」をご覧ください。

IHierarchyData.HasChildren

現在の SiteMapNode オブジェクトが子ノードを持っているかどうかを示す値を取得します。 このメンバーの詳細については、「HasChildren」をご覧ください。

IHierarchyData.Item

階層データ項目を取得します。 このメンバーの詳細については、「Item」をご覧ください。

IHierarchyData.Path

階層データ項目のパスを取得します。 このメンバーの詳細については、「Path」をご覧ください。

IHierarchyData.Type

階層データ項目の型名を表す文字列を取得します。 このメンバーの詳細については、「Type」をご覧ください。

INavigateUIData.Description

サイト マップ ノードの Description プロパティを取得します。 このメンバーの詳細については、「Description」をご覧ください。

INavigateUIData.Name

サイト マップ ノードの Title プロパティを取得します。 このメンバーの詳細については、「Name」をご覧ください。

INavigateUIData.NavigateUrl

サイト マップ ノードの Url プロパティを取得します。 このメンバーの詳細については、「NavigateUrl」をご覧ください。

INavigateUIData.Value

サイト マップ ノードの Title プロパティを取得します。 このメンバーの詳細については、「Value」をご覧ください。

適用対象

こちらもご覧ください