• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

VB.NET HierarchicalDataSourceControl类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了VB.NET中System.Web.UI.HierarchicalDataSourceControl的典型用法代码示例。如果您正苦于以下问题:VB.NET HierarchicalDataSourceControl类的具体用法?VB.NET HierarchicalDataSourceControl怎么用?VB.NET HierarchicalDataSourceControl使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了HierarchicalDataSourceControl类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的VB.NET代码示例。

示例1: New

' 导入命名空间
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

    Public Class FileSystemDataSource
        Inherits HierarchicalDataSourceControl

        Public Sub New()
        End Sub

        Private view As FileSystemDataSourceView = Nothing

        Protected Overrides Function GetHierarchicalView( _
            ByVal viewPath As String) As HierarchicalDataSourceView

            view = New FileSystemDataSourceView(viewPath)
            Return view
        End Function

    End Class
    Public Class FileSystemDataSourceView
        Inherits HierarchicalDataSourceView

        Private _viewPath As String

        Public Sub New(ByVal viewPath As String)
            Dim currentRequest As HttpRequest = HttpContext.Current.Request
            If viewPath = "" Then
                _viewPath = currentRequest.MapPath(currentRequest.ApplicationPath)
            Else
                _viewPath = Path.Combine(currentRequest.MapPath(currentRequest.ApplicationPath), viewPath)
            End If
        End Sub


        ' 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

                Dim rootDirectory As New DirectoryInfo(_viewPath)

                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

    Public Class FileSystemHierarchicalEnumerable
        Inherits ArrayList
        Implements IHierarchicalEnumerable

        Public Sub New()
        End Sub


        Public Overridable Function GetHierarchyData( _
            ByVal enumeratedItem As Object) As IHierarchyData _
            Implements IHierarchicalEnumerable.GetHierarchyData

            Return CType(enumeratedItem, IHierarchyData)
        End Function

    End Class


    Public Class FileSystemHierarchyData
        Implements IHierarchyData

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

        Private fileSystemObject As FileSystemInfo = Nothing

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

        ' 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
End Namespace
开发者ID:VB.NET开发者,项目名称:System.Web.UI,代码行数:181,代码来源:HierarchicalDataSourceControl



注:本文中的System.Web.UI.HierarchicalDataSourceControl类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
VB.NET AutomationPattern类代码示例发布时间:2022-05-24
下一篇:
VB.NET XslTransformFileEditor类代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap