Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5

  Switch on low bandwidth view
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
IHierarchyData Interface

Exposes a node of a hierarchical data structure, including the node object and some properties that describe characteristics of the node. Objects that implement the IHierarchyData interface can be contained in IHierarchicalEnumerable collections, and are used by ASP.NET site navigation and data source controls.

Namespace:  System.Web.UI
Assembly:  System.Web (in System.Web.dll)
Visual Basic (Declaration)
<AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
<AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
Public Interface IHierarchyData
Visual Basic (Usage)
Dim instance As IHierarchyData
C#
[AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public interface IHierarchyData
Visual C++
[AspNetHostingPermissionAttribute(SecurityAction::InheritanceDemand, Level = AspNetHostingPermissionLevel::Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction::LinkDemand, Level = AspNetHostingPermissionLevel::Minimal)]
public interface class IHierarchyData
JScript
public interface IHierarchyData

The IHierarchyData interface is implemented by classes that represent nodes of a hierarchical structure, and track the hierarchical relationships to their parent and child nodes. Classes that implement the IHierarchyData interface can be contained in collections that implement the IHierarchicalEnumerable interface.

The following code example demonstrates how to implement the IHierarchyData interface with a class that wraps a FileSystemInfo object. The FileSystemInfo class is a good example of a hierarchical data node, which the IHierarchyData interface represents for ASP.NET hierarchical data source controls. This code example is part of a larger example provided for the HierarchicalDataSourceControl class.

Visual Basic
Public Class FileSystemHierarchyData
   Implements IHierarchyData

   Public Sub New(obj As FileSystemInfo)
      fileSystemObject = obj
   End Sub 'New

   Private fileSystemObject As FileSystemInfo = Nothing

   Public Overrides Function ToString() As String
      Return fileSystemObject.Name
   End Function 'ToString

   ' IHierarchyData implementation.
   Public Overridable ReadOnly Property HasChildren() As Boolean _
    Implements IHierarchyData.HasChildren
      Get
         If GetType(DirectoryInfo) Is fileSystemObject.GetType() Then
            Dim temp As DirectoryInfo = CType(fileSystemObject, DirectoryInfo)
            Return temp.GetFileSystemInfos().Length > 0
         Else
            Return False
         End If
      End Get
   End Property
   ' DirectoryInfo returns the OriginalPath, while FileInfo returns
   ' a fully qualified path.

   Public Overridable ReadOnly Property Path() As String _
    Implements IHierarchyData.Path
      Get
         Return fileSystemObject.ToString()
      End Get
   End Property

   Public Overridable ReadOnly Property Item() As Object _
    Implements IHierarchyData.Item
      Get
         Return fileSystemObject
      End Get
   End Property

   Public Overridable ReadOnly Property Type() As String _
    Implements IHierarchyData.Type
      Get
         Return "FileSystemData"
      End Get
   End Property

   Public Overridable Function GetChildren() As IHierarchicalEnumerable _
    Implements IHierarchyData.GetChildren
      Dim children As New FileSystemHierarchicalEnumerable()

      If GetType(DirectoryInfo) Is fileSystemObject.GetType() Then
         Dim temp As DirectoryInfo = CType(fileSystemObject, DirectoryInfo)
         Dim fsi As FileSystemInfo
         For Each fsi In  temp.GetFileSystemInfos()
            children.Add(New FileSystemHierarchyData(fsi))
         Next fsi
      End If
      Return children
   End Function 'GetChildren


   Public Overridable Function GetParent() As IHierarchyData _
    Implements IHierarchyData.GetParent
      Dim parentContainer As New FileSystemHierarchicalEnumerable()

      If GetType(DirectoryInfo) Is fileSystemObject.GetType() Then
         Dim temp As DirectoryInfo = CType(fileSystemObject, DirectoryInfo)
         Return New FileSystemHierarchyData(temp.Parent)
      ElseIf GetType(FileInfo) Is fileSystemObject.GetType() Then
         Dim temp As FileInfo = CType(fileSystemObject, FileInfo)
         Return New FileSystemHierarchyData(temp.Directory)
      End If
      ' If FileSystemObj is any other kind of FileSystemInfo, ignore it.
      Return Nothing
   End Function 'GetParent
End Class 'FileSystemHierarchyData

C#
public class FileSystemHierarchyData : IHierarchyData
{
    public FileSystemHierarchyData (FileSystemInfo obj) {
        fileSystemObject = obj;
    }

    private FileSystemInfo fileSystemObject = null;

    public override string ToString() {
        return fileSystemObject.Name;
    }
    // IHierarchyData implementation.
    public bool HasChildren {
        get {
            if (typeof(DirectoryInfo) ==  fileSystemObject.GetType()   ) {
                DirectoryInfo temp = (DirectoryInfo) fileSystemObject;
                return (temp.GetFileSystemInfos().Length > 0);
            }
            else return false;
        }
    }
    // DirectoryInfo returns the OriginalPath, while FileInfo returns
    // a fully qualified path.
    public string Path {
        get {
            return fileSystemObject.ToString();
        }
    }
    public object Item {
        get {
            return fileSystemObject;
        }
    }
    public string Type {
        get {
            return "FileSystemData";
        }
    }
    public IHierarchicalEnumerable GetChildren() {
        FileSystemHierarchicalEnumerable children =
            new FileSystemHierarchicalEnumerable();

        if (typeof(DirectoryInfo) == fileSystemObject.GetType()) {
            DirectoryInfo temp = (DirectoryInfo)fileSystemObject;
            foreach (FileSystemInfo fsi in temp.GetFileSystemInfos()) {
                children.Add(new FileSystemHierarchyData(fsi));
            }
        }
        return children;
    }

    public IHierarchyData GetParent()
    {
        FileSystemHierarchicalEnumerable parentContainer =
            new FileSystemHierarchicalEnumerable();

        if (typeof(DirectoryInfo) == fileSystemObject.GetType())
        {
            DirectoryInfo temp = (DirectoryInfo)fileSystemObject;
            return new FileSystemHierarchyData(temp.Parent);
        }
        else if (typeof(FileInfo) == fileSystemObject.GetType())
        {
            FileInfo temp = (FileInfo)fileSystemObject;
            return new FileSystemHierarchyData(temp.Directory);
        }
        // If FileSystemObj is any other kind of FileSystemInfo, ignore it.
        return null;
    }
}

The following code example demonstrates how to recursively iterate through an IHierarchicalEnumerable collection, extract the IHierarchyData item from the enumerator using the GetHierarchyData method, and perform basic work with the data item.

Visual Basic
<%@ Page Language="VB" AutoEventWireup="true" CodeFile="ihd_1.aspx.vb" Inherits="ihd_1_aspx" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html  >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>

    </div>
    </form>
</body>
</html>

C#
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ihd_1.aspx.cs" Inherits="ihd_1_aspx" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html  >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>

    </div>
    </form>
</body>
</html>

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.

.NET Framework

Supported in: 3.5, 3.0, 2.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker