Export (0) Print
Expand All

HierarchicalDataSourceView.Select Method

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

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

public abstract IHierarchicalEnumerable Select()

Return Value

Type: System.Web.UI.IHierarchicalEnumerable
An IHierarchicalEnumerable collection of data items.

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.

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.

public class FileSystemDataSourceView : HierarchicalDataSourceView
    private string _viewPath;

    public FileSystemDataSourceView(string viewPath)
        HttpRequest currentRequest = HttpContext.Current.Request;
        if (viewPath == "")
            _viewPath = currentRequest.MapPath(currentRequest.ApplicationPath);
            _viewPath = Path.Combine(

    // 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 == "" ||
             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;
            throw new NotSupportedException(
                "The FileSystemDataSource only " +
                "presents data in an authenticated, localhost context.");

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

© 2014 Microsoft