下载中心┊文章中心┊软件分类┊更新软件┊推荐下载┊热门软件┊更新文章┊热门文章
 
《拓文asp.net网站内容管理系统》官方演示站。
 设为首页    
 收藏本站
 作者:黄振安
 
网站首页 开源拓文 .NET编程 网站编程 网页设计 图形图像 数据库 软件工程留言本
    站内搜索:   
您现在的位置: 拓文网络 → 文章中心 → .NET编程 → VB.NET → listview控件显示文件夹[正文]

热 门 文 章

相 关 文 章
  • 用listview显示数据库内某个表...
  • listview控件显示文件夹
     
    [作者:不详    转贴自:不详    点击数:    字体:【大 中 小】    更新时间:2006-2-25 15:14:52]

    Public Sub ShowFiles(ByVal strDirectory As String)
            livPc.BackColor = System.Drawing.SystemColors.ControlLightLight
            ' Save the directory name as a field.
            Me.strDirectory = strDirectory
            livPc.Items.Clear()
            Dim diDirectories As New DirectoryInfo(strDirectory)
            Dim afiFiles() As FileInfo
            Dim fitemp As String
            Dim fisize As String
            Try
                ' Call the convenient GetFiles method to get an array of all files
                ' in the directory.
                afiFiles = diDirectories.GetFiles()
            Catch
                Return
            End Try
            Dim fi As FileInfo
            For Each fi In afiFiles
                ' Create ListViewItem.
                Dim lvi As New ListViewItem(fi.Name)
                If (fi.Attributes And FileAttributes.System) = 0 And (fi.Attributes And FileAttributes.Hidden) = 0 Then
                    ' Assign ImageIndex based on filename extension.
                    Select Case Path.GetExtension(fi.Name).ToUpper()
                        Case ".EXE"
                            lvi.ImageIndex = 16
                        Case ".XLS"
                            lvi.ImageIndex = 17
                        Case ".DOC"
                            lvi.ImageIndex = 21
                        Case ".PDF"
                            lvi.ImageIndex = 20
                        Case ".TXT"
                            lvi.ImageIndex = 14
                        Case Else
                            lvi.ImageIndex = 22
                    End Select
                    ' Add file length and last modified time sub-items.
                    'lvi.SubItems.Add(fi.Length.ToString("N0"))
                    'lvi.SubItems.Add(Format(Math.Ceiling(fi.Length / 1024), "##,##0") & " KB")
     
                    'Get file size accroding with specify format
                    fitemp = CStr(CType((fi.Length), Single) / 1024) 'Conver to single type from string type
     
                    If fi.Length / 1024 = fi.Length \ 1024 Then   '如果文件大小为不带小数位.则在后面加".00KB"
                        fisize = fitemp & ".00 KB"
                    Else
                        If fitemp.Substring(fitemp.LastIndexOf(".") + 1).Length < 2 Then  '如果文件大小为一位小数位.则在后面加".0KB"
                            fisize = Mid(fitemp, 1, fitemp.LastIndexOf(".") + 1) & fitemp.Substring(fitemp.LastIndexOf(".") + 1, 1) & "0 KB"  'Get file size with format as (23.56KB)
                        Else   '如果文件大小为小数位大于或等于两位.则在后面加"KB"
                            fisize = Mid(fitemp, 1, fitemp.LastIndexOf(".") + 1) & fitemp.Substring(fitemp.LastIndexOf(".") + 1, 2) & " KB"  'Get file size with format as (23.56KB)
                        End If
                    End If
                    '--------------------------------------------
                    lvi.SubItems.Add(fisize)
                    lvi.SubItems.Add(Path.GetExtension(fi.Name).ToString)
                    lvi.SubItems.Add(fi.LastWriteTime.ToString())
                    'Add completed ListViewItem to FileListView.
                    livPc.Items.Add(lvi)
                End If
            Next
        End Sub
     

    页次:1/1  1篇/页  首页   上一页   下一页   尾页  合计 1 篇 Go:
     
    上一篇:用listview显示数据库内某个表...
    下一篇:对Cache进行浏览并管理
    winner 打印本页 关闭窗口

         文 章 评 论
    评论人 查看该文章的评论 发表时间
       笔 名* : 0 50分 60分 70分 80分 90分 100分
    评论内容 *: (最多600字。当前字数:0)


    没有相关评论,欢迎您参与!

    - 关于本站 - 网站帮助 - 下载声明 - 友情连接 - 网站地图 -
    Copyright © 2005-2006 myTopWin.Com. All Rights Reserved . [桂ICP备06004496号]