HierarchicalDataSourceView.Select 메서드

정의

뷰의 모든 데이터 항목에 대한 목록을 가져옵니다.Gets a list of all the data items in the view.

public:
 abstract System::Web::UI::IHierarchicalEnumerable ^ Select();
public abstract System.Web.UI.IHierarchicalEnumerable Select ();
abstract member Select : unit -> System.Web.UI.IHierarchicalEnumerable
Public MustOverride Function Select () As IHierarchicalEnumerable

반환

데이터 항목의 IHierarchicalEnumerable 컬렉션입니다.An IHierarchicalEnumerable collection of data items.

예제

다음 코드 예제에서는 재정의 하는 방법에 설명 합니다 Select 에서 파생 된 클래스에서 메서드를 HierarchicalDataSourceView 계층적 검색할 클래스 FileSystemInfo 파일 시스템에서 데이터.The following code example demonstrates how to override the Select method in a class that derives from the HierarchicalDataSourceView class to retrieve hierarchical FileSystemInfo data from a file system. 보안상의 이유로 파일 시스템 정보의 데이터 소스 컨트롤 localhost에서 사용 중인 경우에 표시 됩니다, 시나리오에서는 인증 및 데이터 소스 컨트롤을 사용 하 여 Web Forms 페이지에 있는 가상 디렉터리에만 시작 됩니다.For security purposes, file system information is displayed only if the data source control is being used in a localhost, authenticated scenario, and only starts with the virtual directory that the Web Forms page using the data source control resides in. 그렇지 않은 경우는 viewPath 뷰 개체의 생성자에 전달 된 매개 변수는 현재 파일 시스템 경로 기준으로 보기를 만드는 데 사용할 수 있습니다.Otherwise, the viewPath parameter passed to the constructor of the view object might be used to create a view based on the current file system path. 이 코드 예제는에 대해 제공 된 큰 예제의 일부는 HierarchicalDataSourceControl 클래스입니다.This code example is part of a larger example provided for the HierarchicalDataSourceControl class.

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

설명

합니다 Select 메서드가 반환 되는 IHierarchicalEnumerable 현재 보기에서 데이터 항목의 컬렉션입니다.The Select method returns an IHierarchicalEnumerable collection of data items in the current view. 호출할 수 있습니다 합니다 GetEnumerator 메서드를는 IEnumerator 개체 및 데이터 항목의 컬렉션을 반복 합니다.You can call the GetEnumerator method to get an IEnumerator object and iterate through the collection of data items.

적용 대상

추가 정보