HierarchicalDataSourceView.Select Methode

Definition

Ruft eine Liste aller Datenelemente in der Ansicht ab.

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

Gibt zurück

IHierarchicalEnumerable

Eine IHierarchicalEnumerable-Auflistung von Datenelementen.

Beispiele

Im folgenden Codebeispiel wird veranschaulicht, wie sie die Methode in einer Klasse überschreiben, die Select von der HierarchicalDataSourceView Klasse abgeleitet wird, um hierarchische FileSystemInfo Daten aus einem Dateisystem abzurufen. Für Sicherheitszwecke werden Dateisysteminformationen nur angezeigt, wenn das Datenquellensteuerelement in einem lokalen Host, authentifizierten Szenario verwendet wird und nur mit dem virtuellen Verzeichnis beginnt, in dem sich die Web Forms Seite mit dem Datenquellensteuerelement befindet. Andernfalls kann der viewPath an den Konstruktor des Ansichtsobjekts übergebene Parameter verwendet werden, um eine Ansicht basierend auf dem aktuellen Dateisystempfad zu erstellen. Dieses Codebeispiel ist Teil eines größeren Beispiels, das für die HierarchicalDataSourceControl Klasse bereitgestellt wird.

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

Hinweise

Die Select Methode gibt eine IHierarchicalEnumerable Auflistung von Datenelementen in der aktuellen Ansicht zurück. Sie können die GetEnumerator Methode aufrufen, um ein IEnumerator Objekt abzurufen und durch die Sammlung von Datenelementen zu durchlaufen.

Gilt für

Siehe auch