HierarchicalDataSourceView.Select メソッド
アセンブリ: System.Web (system.web.dll 内)

Dim instance As HierarchicalDataSourceView Dim returnValue As IHierarchicalEnumerable returnValue = instance.Select
データ項目の IHierarchicalEnumerable コレクション。

Select メソッドでは、現在のビュー内のデータ項目の IHierarchicalEnumerable コレクションが返されます。GetEnumerator メソッドを呼び出して IEnumerator オブジェクトを取得することにより、データ項目のコレクションを反復処理できます。

次のコード例では、HierarchicalDataSourceView クラスから派生したクラスの Select メソッドをオーバーライドし、ファイル システムから FileSystemInfo の階層データを取得する方法を示します。セキュリティ上の理由で、ファイル システム情報が表示されるのは、データ ソース コントロールが、ローカルホスト上で認証された状態で使用されており、そのデータ ソース コントロールを使用する 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."); } } }

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.Select メソッドのページへのリンク