SiteMapNode クラスとは? わかりやすく解説

SiteMapNode クラス

メモ : このクラスは、.NET Framework version 2.0新しく追加されたものです。

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

名前空間: System.Web
アセンブリ: System.Web (system.web.dll 内)
構文構文

Public Class SiteMapNode
    Implements ICloneable, IHierarchyData, INavigateUIData
public class SiteMapNode : ICloneable, IHierarchyData,
 INavigateUIData
public ref class SiteMapNode : ICloneable,
 IHierarchyData, INavigateUIData
public class SiteMapNode implements ICloneable,
 IHierarchyData, 
    INavigateUIData
public class SiteMapNode implements ICloneable,
 IHierarchyData, 
    INavigateUIData
解説解説

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

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

使用例使用例

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

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

' 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

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

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

このコード例は、SiteMapProvider クラストピック取り上げているコード例一部分です。

  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 'LoadSiteMapFromStore
End Class 'SimpleTextSiteMapProvider
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 &&
                (null == nodeValues[3] || nodeValues[3] == String.Empty))
            {
              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;
}
.NET Framework のセキュリティ.NET Frameworkセキュリティ
継承階層継承階層
System.Object
  System.Web.SiteMapNode
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「SiteMapNode クラス」の関連用語

SiteMapNode クラスのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



SiteMapNode クラスのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS