SiteMapNode クラス
アセンブリ: System.Web (system.web.dll 内)


SiteMapNode オブジェクトは、サイト マップ構造内の Web サイト ページを表します。SiteMapNode オブジェクトは、サイト マップ データを永続ストレージからメモリに読み込むために、SiteMap 静的クラスによって 1 つ以上のサイト マップ プロバイダを使用して実行時に読み込まれます。SiteMapNode オブジェクトは、SiteMapNodeItem クラスによってラップされ、SiteMapPath コントロールなどの Web サーバー コントロールによって使用されます。
SiteMapNode クラスには、Web サイトの単一ページの記述に使用するいくつかのプロパティが含まれています。Url、Title、および 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; }


System.Web.SiteMapNode


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
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- SiteMapNode クラスのページへのリンク