System.Web.UI Namespace


.NET Framework Class Library
HierarchicalDataSourceView Class

Represents a data view on a node or collection of nodes in a hierarchical data structure for a HierarchicalDataSourceControl control.

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

Visual Basic (Declaration)
<AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
<AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
Public MustInherit Class HierarchicalDataSourceView
Visual Basic (Usage)
Dim instance As HierarchicalDataSourceView
C#
[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public abstract class HierarchicalDataSourceView
Visual C++
[AspNetHostingPermissionAttribute(SecurityAction::LinkDemand, Level = AspNetHostingPermissionLevel::Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction::InheritanceDemand, Level = AspNetHostingPermissionLevel::Minimal)]
public ref class HierarchicalDataSourceView abstract
JScript
public abstract class HierarchicalDataSourceView
Remarks

ASP.NET supports a data-binding architecture that enables Web server controls to bind to data and present it in a consistent fashion. Web server controls that bind to data are called data-bound controls, and the classes that facilitate that binding are called data source controls. Data source controls can represent any data source: a file, a stream, a relational database, a business object, and so on. Data source controls present data in a consistent way to data-bound controls, regardless of the source or format of the underlying data.

Data source controls that represent hierarchical data derive from the abstract HierarchicalDataSourceControl class. You can think of a data source control as the combination of the data source control object and its associated views on the underlying data, which are represented by data source view objects. Hierarchical data source controls support a hierarchical data source view for each hierarchical level of data they represent. The data source views are not named, like the DataSourceView objects associated with a DataSourceControl control, but are identified by their unique hierarchical path.

Data source views define the capabilities of a data source control. All data source view objects, including HierarchicalDataSourceView, support data retrieval from the underlying data source using the Select method, which retrieves a hierarchical list of data as an IHierarchicalEnumerable object. All data source view objects optionally support a basic set of capabilities, including operations such as Insert, Update, Delete, and sorting. A data-bound control can discover the capabilities of a data source control by retrieving an associated data source view using the GetHierarchicalView method and querying the view at design time or at run time. HierarchicalDataSourceView does not currently support Insert, Update or Delete operations.

Notes to Inheritors:

When you inherit from HierarchicalDataSourceView, you must override the following member: Select.

Examples

The following code example demonstrates how to derive a class from the HierarchicalDataSourceView class to retrieve data from hierarchical data storage, in this case a file system. The FileSystemDataSourceView class is a strongly typed HierarchicalDataSourceView instance that enables hierarchical Web server controls such as the TreeView control to bind to a FileSystemDataSource control and display file system information. 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 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.");
            }
        }
    }
.NET Framework Security

Inheritance Hierarchy

System..::.Object
  System.Web.UI..::.HierarchicalDataSourceView
    System.Web.UI.WebControls..::.SiteMapHierarchicalDataSourceView
    System.Web.UI.WebControls..::.XmlHierarchicalDataSourceView
Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Platforms

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Version Information

.NET Framework

Supported in: 3.5, 3.0, 2.0
See Also

Reference

Tags :


Page view tracker