HierarchicalDataSourceView クラス

定義

ノードまたはノードのコレクションのデータ ビューを、HierarchicalDataSourceControl コントロールの階層データ構造で表します。

public ref class HierarchicalDataSourceView abstract
public abstract class HierarchicalDataSourceView
type HierarchicalDataSourceView = class
Public MustInherit Class HierarchicalDataSourceView
継承
HierarchicalDataSourceView
派生

次のコード例は、クラスから HierarchicalDataSourceView クラスを派生して階層データ ストレージ (この場合はファイル システム) からデータを取得する方法を示しています。 この FileSystemDataSourceView クラスは、厳密に型指定された HierarchicalDataSourceView インスタンスであり、コントロールなどの階層 Web サーバー コントロールが TreeView コントロールに FileSystemDataSource バインドされ、ファイル システム情報を表示できるようになります。 セキュリティ上の理由から、ファイル システム情報は、データ ソース管理が localhost、認証済みのシナリオで使用されている場合にのみ表示され、データ ソース管理を使用するWeb Forms ページが存在する仮想ディレクトリでのみ開始されます。 それ以外の viewPath 場合、コンストラクターに渡されるパラメーターを使用して、現在のファイル システム パスに基づくビューを作成できます。 このコード例は、HierarchicalDataSourceControl クラスのために提供されている大規模な例の一部です。

public class FileSystemDataSourceView : HierarchicalDataSourceView
{
    private string _viewPath;

    public FileSystemDataSourceView(string viewPath)
    {
        HttpRequest currentRequest = HttpContext.Current.Request;
        if (viewPath == "")
        {
            _viewPath = currentRequest.MapPath(currentRequest.ApplicationPath);
        }
        else
        {
            _viewPath = Path.Combine(
                currentRequest.MapPath(currentRequest.ApplicationPath),
                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"))
        {
            DirectoryInfo rootDirectory = new DirectoryInfo(_viewPath);
            if (!rootDirectory.Exists)
            {
                return null;
            }

            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.");
        }
    }
}
Public Class FileSystemDataSourceView
    Inherits HierarchicalDataSourceView

    Private _viewPath As String

    Public Sub New(ByVal viewPath As String)
        Dim currentRequest As HttpRequest = HttpContext.Current.Request
        If viewPath = "" Then
            _viewPath = currentRequest.MapPath(currentRequest.ApplicationPath)
        Else
            _viewPath = Path.Combine(currentRequest.MapPath(currentRequest.ApplicationPath), viewPath)
        End If
    End Sub


    ' 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

            Dim rootDirectory As New DirectoryInfo(_viewPath)

            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

注釈

ASP.NET は、Web サーバー コントロールがデータにバインドし、一貫した方法でデータを提示できるようにするデータ バインディング アーキテクチャをサポートしています。 データにバインドする Web サーバー コントロールはデータ バインド コントロールと呼ばれ、そのバインドを容易にするクラスはデータ ソース コントロールと呼ばれます。 データ ソース コントロールは、ファイル、ストリーム、リレーショナル データベース、ビジネス オブジェクトなどの任意のデータ ソースを表すことができます。 データ ソース コントロールは、基になるデータのソースまたは形式に関係なく、データ バインド コントロールに対して一貫した方法でデータを提示します。

階層データを表すデータ ソース コントロールは、抽象 HierarchicalDataSourceControl クラスから派生します。 データ ソース コントロールは、データ ソース ビュー オブジェクトによって表される基になるデータに対するデータ ソース管理オブジェクトとそれに関連付けられたビューの組み合わせと考えることができます。 階層データ ソース コントロールは、それらが表すデータの階層レベルごとに階層データ ソース ビューをサポートします。 データ ソース ビューは、コントロールに DataSourceView 関連付けられているオブジェクトのように名前は付 DataSourceControl けされませんが、一意の階層パスによって識別されます。

データ ソース ビューは、データ ソース コントロールの機能を定義します。 含むすべての HierarchicalDataSourceViewデータ ソース ビュー オブジェクトは、データの階層リストをオブジェクトとして取得するメソッドを Select 使用して、基になるデータ ソースからのデータ取得を IHierarchicalEnumerable サポートします。 すべてのデータ ソース ビュー オブジェクトは、必要に応じて、操作 (、、UpdateDelete、、並べ替えなど) をInsert含む基本的な一連の機能をサポートします。 データ バインド コントロールは、メソッドを使用して GetHierarchicalView 関連付けられているデータ ソース ビューを取得し、デザイン時または実行時にビューにクエリを実行することで、データ ソース コントロールの機能を検出できます。 HierarchicalDataSourceViewは現在サポートInsertUpdateされていません。またはDelete操作です。

注意 (実装者)

HierarchicalDataSourceView から継承する場合は、Select() のメンバーをオーバーライドする必要があります。

コンストラクター

HierarchicalDataSourceView()

HierarchicalDataSourceView クラスの新しいインスタンスを初期化します。

メソッド

Equals(Object)

指定されたオブジェクトが現在のオブジェクトと等しいかどうかを判断します。

(継承元 Object)
GetHashCode()

既定のハッシュ関数として機能します。

(継承元 Object)
GetType()

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

(継承元 Object)
MemberwiseClone()

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

(継承元 Object)
Select()

ビュー内のすべてのデータ項目の一覧を取得します。

ToString()

現在のオブジェクトを表す文字列を返します。

(継承元 Object)

適用対象

こちらもご覧ください