⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 search.aspx.vb

📁 是可以运行的电子光盘 有程序与PPT介绍 对于学习VB。NET的有参考意义
💻 VB
字号:
Imports System.Data
Imports System.io
Partial Class FileManager_Search
    Inherits WebDiskBasePage

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Me.IsPostBack Then
            Session("SortName") = "Name"
            Session("SortAscending") = "yes"
            FillGridView()
        End If

    End Sub
    '填充指定目录下的目录和文件到GridView中
    Private Sub FillGridView()
        Dim FileDirName As String = Server.UrlDecode(Request.Params("Content"))
        Dim FS As New FileSearch(New IO.DirectoryInfo(Session("UserDir")), FileDirName)
        FS.Search()

        Dim dt As DataTable = New DataTable
        Dim dataRow As DataRow
        dt.Columns.Add(New DataColumn("Name", System.Type.GetType("System.String")))
        dt.Columns.Add(New DataColumn("Path", System.Type.GetType("System.String")))
        dt.Columns.Add(New DataColumn("Extension", System.Type.GetType("System.String")))
        dt.Columns.Add(New DataColumn("Length", System.Type.GetType("System.String")))
        dt.Columns.Add(New DataColumn("CreationTime", System.Type.GetType("System.String")))

        '装载目录
        'For Each tempdirInfo As DirectoryInfo In FS.Directories
        '    dataRow = dt.NewRow
        '    dataRow(0) = tempdirInfo.FullName
        '    dataRow(1) = "~/images/folder.ico"
        '    dataRow(2) = FileDirServer.FormatSize(FileDirServer.GetDirectorySize(tempdirInfo))
        '    dataRow(3) = tempdirInfo.CreationTime
        '    dt.Rows.Add(dataRow)
        'Next
        '装载文件
        For Each tempFileInfo As FileInfo In FS.Files
            dataRow = dt.NewRow
            '把全路径中,路径和文件名分离

            dataRow("Name") = Path.GetFileName(tempFileInfo.FullName)
            dataRow("Path") = Path.GetDirectoryName(tempFileInfo.FullName)
            dataRow("Extension") = "~/filetype/" & Mid(tempFileInfo.Extension, 2) & ".gif"
            dataRow("Length") = FileDirServer.FormatSize(tempFileInfo.Length)
            dataRow("CreationTime") = tempFileInfo.CreationTime
            dt.Rows.Add(dataRow)
        Next

        Dim dv As DataView = dt.DefaultView
        If Session("SortAscending") = "yes" Then
            dv.Sort = Session("SortName") + " ASC"
        Else
            dv.Sort = Session("SortName") + " DESC"
        End If
        GridView1.DataSource = dv
        GridView1.DataBind()
    End Sub
    Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
        If e.Row.RowType = DataControlRowType.DataRow Then
            Dim location As String
            '合并路径和文件名
            Dim hy As HyperLink = CType(e.Row.FindControl("NameLink"), HyperLink)
            Dim li As Literal = CType(e.Row.FindControl("Path"), Literal)
            location = Path.Combine(li.Text, hy.Text)
            If File.Exists(location) Then 'location文件存在
                hy.NavigateUrl = "MainFile.aspx?Folder=" & Server.UrlEncode(location)
                hy.NavigateUrl = "Download.aspx?File=" & Server.UrlEncode(location) '对中文进行编码
                Dim EditLink As HyperLink = CType(e.Row.FindControl("EditLink"), HyperLink)
                Dim fi As New FileInfo(location)
                '判断是否是文本文件
                If FileDirServer.IsTextFile(fi.Extension.ToLower, Server.MapPath(Data.C_TextExtendXmlMapPath)) Then
                    EditLink.Visible = True
                    EditLink.NavigateUrl = "EditFile.aspx?File=" & Server.UrlEncode(location)  '对中文进行编码
                End If
            End If

        End If
    End Sub

    Protected Sub GridView1_Sorting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSortEventArgs) Handles GridView1.Sorting
        WebPageShare.GridViewSort(GridView1, e)
        FillGridView()
    End Sub

    Protected Sub Page_Unload(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Unload
        Session("FileSearch") = Nothing
    End Sub
End Class

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -