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


ASP.NET では、Web サーバー コントロールをデータにバインドして、一貫した方式で提供できるようにするデータ バインディング アーキテクチャがサポートされています。データにバインドされる Web サーバー コントロールをデータ バインド コントロールといいます。また、そのバインディングを容易にするクラスをデータ ソース コントロールといいます。データ ソース コントロールは、ファイル、ストリーム、リレーショナル データベース、ビジネス オブジェクトなど、あらゆるデータ ソースを表すことができます。データ ソース コントロールにより、基になるデータのソースや形式にかかわらず、一貫した方式でデータがデータ バインド コントロールに提供されます。
階層データを表すデータ ソース コントロールは、HierarchicalDataSourceControl 抽象クラスから派生しています。データ ソース コントロールは、データ ソース コントロール オブジェクトと、それに関連付けられた、基になるデータのビューを組み合わせたものと考えることができます。ビューは、データ ソース ビュー オブジェクトによって表されます。階層構造のデータ ソース コントロールでは、それらのコントロールによって表されるデータの各階層レベルに対して、階層構造のデータ ソース ビューがサポートされます。データ ソース ビューは、DataSourceControl コントロールに関連付けられている DataSourceView オブジェクトのような名前が付けられていませんが、一意の階層パスによって識別できます。
データ ソース ビューでは、データ ソース コントロールの機能が定義されます。HierarchicalDataSourceView を含むすべてのデータ ソース ビュー オブジェクトでは、基になるデータ ソースからのデータの取得がサポートされます。データの取得は、データの階層リストを IHierarchicalEnumerable オブジェクトとして取得する Select メソッドを使用して行われます。すべてのデータ ソース ビュー オブジェクトには、Insert、Update、Delete、並べ替えなどの操作を含む、一連の基本的な機能がオプションとして用意されています。データ バインド コントロールにより、データ ソース コントロールの機能を検出できます。この操作は、データ ソース コントロールに関連付けられたデータ ソース ビューを GetHierarchicalView メソッドを使用して取得し、デザイン時または実行時にそのビューにクエリすることによって実行できます。HierarchicalDataSourceView では、現在 Insert、Update または Delete の操作がサポートされていません。
継承時の注意 HierarchicalDataSourceView から継承する場合は、Select のメンバをオーバーライドする必要があります。
次のコード例では、HierarchicalDataSourceView クラスからクラスを派生して、階層構造のデータ ストレージ (この場合はファイル システム) からデータを取得する方法を示します。FileSystemDataSourceView クラスは、厳密に型指定された HierarchicalDataSourceView インスタンスです。このインスタンスを使用すると、TreeView コントロールなどの階層構造の Web サーバー コントロールを FileSystemDataSource コントロールにバインドしてファイル システム情報を表示できるようになります。セキュリティ上の理由で、ファイル システム情報が表示されるのは、データ ソース コントロールが、ローカルホスト上で認証された状態で使用されており、そのデータ ソース コントロールを使用する Web フォーム ページが存在する仮想ディレクトリでのみ起動する場合に限られます。それ以外の場合は、コンストラクタに渡された viewPath パラメータが使用され、現在のファイル システム パスに基づいてビューが作成されます。このコード例は、HierarchicalDataSourceControl クラスのトピックで取り上げているコード例の一部分です。
' The FileSystemDataSourceView class encapsulates the ' capabilities of the FileSystemDataSource data source control. Public Class FileSystemDataSourceView Inherits HierarchicalDataSourceView Private _viewPath As String Public Sub New(viewPath As String) ' This implementation of HierarchicalDataSourceView does not ' use the viewPath parameter but other implementations ' could make use of it for retrieving values. _viewPath = viewPath End Sub 'New ' Starting with the rootNode, recursively build a list of ' FileSystemInfo nodes, create FileSystemHierarchyData ' objects, add them all to the FileSystemHierarchicalEnumerable, ' and return the list. Public Overrides Function [Select]() As IHierarchicalEnumerable Dim currentRequest As HttpRequest = HttpContext.Current.Request ' SECURITY: There are many security issues that can be raised ' SECURITY: by exposing the file system structure of a Web server ' SECURITY: to an anonymous user in a limited trust scenario such as ' SECURITY: a Web page served on an intranet or the Internet. ' SECURITY: For this reason, the FileSystemDataSource only ' SECURITY: shows data when the HttpRequest is received ' SECURITY: from a local Web server. In addition, the data source ' SECURITY: does not display data to anonymous users. If currentRequest.IsAuthenticated AndAlso(currentRequest.UserHostAddress = "127.0.0.1" OrElse currentRequest.UserHostAddress = "::1") Then ' The ApplicationPath returns a physical path in VB, so do not MapPath. Dim rootPath As String = currentRequest.MapPath(currentRequest.ApplicationPath) Dim rootDirectory As New DirectoryInfo(rootPath) Dim fshe As New FileSystemHierarchicalEnumerable() Dim fsi As FileSystemInfo For Each fsi In rootDirectory.GetFileSystemInfos() fshe.Add(New FileSystemHierarchyData(fsi)) Next fsi Return fshe Else Throw New NotSupportedException("The FileSystemDataSource only " + "presents data in an authenticated, localhost context.") End If End Function 'Select End Class 'FileSystemDataSourceView
// The FileSystemDataSourceView class encapsulates the // capabilities of the FileSystemDataSource data source control. public class FileSystemDataSourceView : HierarchicalDataSourceView { private string _viewPath; public FileSystemDataSourceView(string viewPath) { // This implementation of HierarchicalDataSourceView does not // use the viewPath parameter but other implementations // could make use of it for retrieving values. _viewPath = viewPath; } // Starting with the rootNode, recursively build a list of // FileSystemInfo nodes, create FileSystemHierarchyData // objects, add them all to the FileSystemHierarchicalEnumerable , // and return the list. public override IHierarchicalEnumerable Select() { HttpRequest currentRequest = HttpContext.Current.Request; // SECURITY: There are many security issues that can be raised // SECURITY: by exposing the file system structure of a Web server // SECURITY: to an anonymous user in a limited trust scenario such as // SECURITY: a Web page served on an intranet or the Internet. // SECURITY: For this reason, the FileSystemDataSource only // SECURITY: shows data when the HttpRequest is received // SECURITY: from a local Web server. In addition, the data source // SECURITY: does not display data to anonymous users. if ( currentRequest.IsAuthenticated && (currentRequest.UserHostAddress == "127.0.0.1" || currentRequest.UserHostAddress == "::1")) { string rootPath = currentRequest.MapPath (currentRequest.ApplicationPath); DirectoryInfo rootDirectory = new DirectoryInfo(rootPath); FileSystemHierarchicalEnumerable fshe = new FileSystemHierarchicalEnumerable(); foreach (FileSystemInfo fsi in rootDirectory.GetFileSystemInfos()) { fshe.Add(new FileSystemHierarchyData(fsi)); } return fshe; } else { throw new NotSupportedException("The FileSystemDataSource only " + "presents data in an authenticated, localhost context."); } } }


System.Web.UI.HierarchicalDataSourceView
System.Web.UI.WebControls.SiteMapHierarchicalDataSourceView
System.Web.UI.WebControls.XmlHierarchicalDataSourceView


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


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