.NET Framework Class Library
HierarchicalDataSourceView.Select Method

Note: This method is new in the .NET Framework version 2.0.

Gets a list of all the data items in the view.

Namespace: System.Web.UI
Assembly: System.Web (in system.web.dll)

Syntax

Visual Basic (Declaration)
Public MustOverride Function Select As IHierarchicalEnumerable
Visual Basic (Usage)
Dim instance As HierarchicalDataSourceView
Dim returnValue As IHierarchicalEnumerable

returnValue = instance.Select
C#
public abstract IHierarchicalEnumerable Select ()
C++
public:
virtual IHierarchicalEnumerable^ Select () abstract
J#
public abstract IHierarchicalEnumerable Select ()
JScript
public abstract function Select () : IHierarchicalEnumerable

Return Value

An IHierarchicalEnumerable collection of data items.
Remarks

The Select method returns an IHierarchicalEnumerable collection of data items in the current view. You can call the GetEnumerator method to get an IEnumerator object and iterate through the collection of data items.

Example

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. 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. 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. This code example is part of a larger example provided for the HierarchicalDataSourceControl class.

Visual Basic
' 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
C#
// 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.");
        }
    }
}
Platforms

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

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

Version Information

.NET Framework

Supported in: 2.0
See Also

Tags :


Page view tracker