HierarchicalDataSourceControl クラスとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > HierarchicalDataSourceControl クラスの意味・解説 

HierarchicalDataSourceControl クラス

メモ : このクラスは、.NET Framework version 2.0新しく追加されたものです。

階層データを表すデータ ソース コントロール基本クラス提供します

名前空間: System.Web.UI
アセンブリ: System.Web (system.web.dll 内)
構文構文

<BindableAttribute(False)> _
Public MustInherit Class
 HierarchicalDataSourceControl
    Inherits Control
    Implements IHierarchicalDataSource
Dim instance As HierarchicalDataSourceControl
[BindableAttribute(false)] 
public abstract class HierarchicalDataSourceControl
 : Control, IHierarchicalDataSource
[BindableAttribute(false)] 
public ref class HierarchicalDataSourceControl
 abstract : public Control, IHierarchicalDataSource
/** @attribute BindableAttribute(false) */ 
public abstract class HierarchicalDataSourceControl
 extends Control implements IHierarchicalDataSource
BindableAttribute(false) 
public abstract class HierarchicalDataSourceControl
 extends Control implements IHierarchicalDataSource
解説解説

ASP.NET では、Web サーバー コントロールデータバインドして、データ一貫した方式提供できるようにするコントロール データ バインディング アーキテクチャサポートされています。データバインドされる Web サーバー コントロールデータ バインド コントロールいいますまた、そのバインディング容易にするクラスデータ ソース コントロールいいますデータ ソース コントロールは、ファイルストリームリレーショナル データベースビジネス オブジェクトなど、あらゆるデータ ソースを表すことができますデータ ソース コントロールにより、基になるデータソース形式かかわらず一貫した方式データデータ バインド コントロール提供されます。

階層データを表すデータ ソース コントロールHierarchicalDataSourceControl クラスから派生します。データリストまたはテーブルを表すデータ ソース コントロールについては DataSourceControl クラスからの派生なりますHierarchicalDataSourceControl クラスは、IHierarchicalDataSource インターフェイス基本実装なります。このインターフェイスは、データ ソース コントロール関連付けられた階層データ ソース ビュー オブジェクト取得するメソッド GetHierarchicalView を 1 つ定義します

データ ソース コントロールは、HierarchicalDataSourceControl オブジェクトに、そのオブジェクト関連付けられたデータ ソース ビュー オブジェクト呼ばれるビュー組み合わせたものと考えることができます。表形式データを表すデータ ソース コントロールは、通常 1 つの名前付ビュー関連付けられますが、HierarchicalDataSourceControl クラスでは、データ ソース コントロールが表す階層データレベルごとのデータ ソース ビューサポートします階層データレベル一意階層パスによって識別され、GetHierarchicalView メソッドviewPath パラメータ渡されます。各 HierarchicalDataSourceView オブジェクトは、表される階層レベル対すデータ ソース コントロール機能定義し挿入更新削除並べ替えなどの操作実行します

HierarchicalDataBoundControl クラスから派生した TreeView などの Web サーバー コントロールが、階層データ ソース コントロール使用して階層データバインドます。

データ ソース コントロールは、宣言による永続化有効にして、オプションで、状態管理を行うためのコントロールとして実装されますデータ ソース コントロール視覚的に表示されないため、テーマサポートしません。

使用例使用例

抽象 HierarchicalDataSourceControl クラスHierarchicalDataSourceView クラス拡張し、IHierarchicalEnumerable インターフェイスと IHierarchyData インターフェイス実装して、ファイル システム情報取得する階層データ ソース コントロール作成する方法次のコード例示しますFileSystemDataSource コントロールによって、Web サーバー コントロールは FileSystemInfo オブジェクトバインドされ、基本ファイル システム情報表示できます。この例の FileSystemDataSource クラスは、GetHierarchicalView メソッド実装提供してます。このメソッドによって、FileSystemDataSourceView オブジェクト取得されます。FileSystemDataSourceView オブジェクトは、基のデータ ストレージからデータ取得します。この場合は、Web サーバー上のファイル システム情報なりますセキュリティ上の理由で、ファイル システム情報表示されるのは、データ ソース コントロールが、ローカルホスト上で認証された状態で使用されており、そのデータ ソース コントロール使用する Web フォーム ページ存在する仮想ディレクトリでのみ起動する場合限られます。最後にFileSystemDataSource使用する FileSystemInfo オブジェクトラップするための、IHierarchicalEnumerableIHierarchyData実装する 2 つクラス提供されています。

Imports System
Imports System.Collections
Imports System.IO
Imports System.Runtime.InteropServices
Imports System.Security.Permissions
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls

Namespace Samples.AspNet

<AspNetHostingPermission(SecurityAction.Demand, Level:=AspNetHostingPermissionLevel.Minimal)>
 _
Public Class FileSystemDataSource
   Inherits HierarchicalDataSourceControl

   Public Sub New()
   End Sub 'New
   ' Return a strongly typed view for the current data source control.
   Private view As FileSystemDataSourceView
 = Nothing

   Protected Overrides Function
 GetHierarchicalView(viewPath As String) As
 HierarchicalDataSourceView
      If view Is Nothing
 Then
         view = New FileSystemDataSourceView(viewPath)
      End If
      Return view
   End Function 'GetHierarchicalView

End Class 'FileSystemDataSource
' 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
' A collection of FileSystemHierarchyData objects

Public Class FileSystemHierarchicalEnumerable
   Inherits ArrayList
   Implements IHierarchicalEnumerable

   Public Sub New()
   End Sub 'New


   Public Overridable Function
 GetHierarchyData(enumeratedItem As Object)
 As IHierarchyData _
    Implements IHierarchicalEnumerable.GetHierarchyData
      Return CType(enumeratedItem, IHierarchyData)
   End Function 'GetHierarchyData

End Class 'FileSystemHierarchicalEnumerable


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
   ' 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
End Namespace
using System;
using System.Collections;
using System.IO;
using System.Runtime.InteropServices;
using System.Security.Permissions;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

[AspNetHostingPermission(SecurityAction.Demand, Level=AspNetHostingPermissionLevel.Minimal)]
public class FileSystemDataSource : HierarchicalDataSourceControl,
 IHierarchicalDataSource
{
    public FileSystemDataSource() : base()
 {}

    // Return a strongly typed view for the current data source control.
    private FileSystemDataSourceView view = null;
    protected override HierarchicalDataSourceView GetHierarchicalView(string
 viewPath) {
        if (null == view) {
            view = new FileSystemDataSourceView(viewPath);
        }
        return view;
    }

    // The FileSystemDataSource can be used declaratively. To enable
    // declarative use, override the default implementation of
    // CreateControlCollection to return a ControlCollection that
    // you can add to.
    protected override ControlCollection CreateControlCollection()
 {
        return new ControlCollection(this);
    }
}
// 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.");
        }
    }
}
// A collection of FileSystemHierarchyData objects
public class FileSystemHierarchicalEnumerable
 : ArrayList, IHierarchicalEnumerable
{
    public FileSystemHierarchicalEnumerable () : base
 (){
    }

    public IHierarchyData GetHierarchyData(object enumeratedItem)
 {
        return enumeratedItem as IHierarchyData;
    }
}

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;
    }
}

FileSystemDataSource の例を使用して宣言により TreeView コントロールファイル システム データバインドする方法次のコード例示します

Imports System
Imports System.Collections
Imports System.IO
Imports System.Runtime.InteropServices
Imports System.Security.Permissions
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls

Namespace Samples.AspNet.VB

<AspNetHostingPermission(SecurityAction.Demand, Level:=AspNetHostingPermissionLevel.Minimal)>
 _
Public Class FileSystemDataSource
   Inherits HierarchicalDataSourceControl

   Public Sub New()
   End Sub 'New
   ' Return a strongly typed view for the current data source control.
   Private view As FileSystemDataSourceView
 = Nothing

   Protected Overrides Function
 GetHierarchicalView(viewPath As String) As
 HierarchicalDataSourceView
      If view Is Nothing
 Then
         view = New FileSystemDataSourceView(viewPath)
      End If
      Return view
   End Function 'GetHierarchicalView

End Class 'FileSystemDataSource
using System;
using System.Collections;
using System.IO;
using System.Runtime.InteropServices;
using System.Security.Permissions;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

[AspNetHostingPermission(SecurityAction.Demand, Level=AspNetHostingPermissionLevel.Minimal)]
public class FileSystemDataSource : HierarchicalDataSourceControl,
 IHierarchicalDataSource
{
    public FileSystemDataSource() : base()
 {}

    // Return a strongly typed view for the current data source control.
    private FileSystemDataSourceView view = null;
    protected override HierarchicalDataSourceView GetHierarchicalView(string
 viewPath) {
        if (null == view) {
            view = new FileSystemDataSourceView(viewPath);
        }
        return view;
    }

    // The FileSystemDataSource can be used declaratively. To enable
    // declarative use, override the default implementation of
    // CreateControlCollection to return a ControlCollection that
    // you can add to.
    protected override ControlCollection CreateControlCollection()
 {
        return new ControlCollection(this);
    }
}
.NET Framework のセキュリティ.NET Frameworkセキュリティ
継承階層継承階層
System.Object
   System.Web.UI.Control
    System.Web.UI.HierarchicalDataSourceControl
       System.Web.UI.WebControls.SiteMapDataSource
       System.Web.UI.WebControls.XmlDataSource
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「HierarchicalDataSourceControl クラス」の関連用語

HierarchicalDataSourceControl クラスのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



HierarchicalDataSourceControl クラスのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS