All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
XMLHTTP 对象及其方法简介_[XML教程]
ASP.Net基础学习,HTML控件,简单介绍_[Asp.Net教程]
升级PHP5的理由:PHP4和PHP5性能对比_php资料_编程技术
用最有效的方式来扩大你网站的名声_JavaScript技术_编程技术
SQL,SERVER中字段类型及说明_mssql学习_编程技术
asp.net:将多次查询的数据填充到同一数据源_[Asp.Net教程]
Asp.net,Ajax-我可以用javascript做些什么?_[Asp.Net教程]
ASP.NET,2.0后台代码与内联代码的对比_[Asp.Net教程]
数据库维护_[SQL,Server教程]
技巧:ASP.NET设计中的性能优化问题_.net资料_编程技术
Reading number is top 10 pictures
Abdominal hit by iron--HangZhou best driver parking save passengers
Beauty ZhiHuiLin2
Plump, too plump!1
The world first motorcycle will be auctioned for 21000 pounds
Beautiful vacuum girl2
移民小国也实惠2
The money of more than 100 countries and regions7
Plump, too plump!2
Sora aoi mirror memorial classics2
两个妞在等世界上最短的火车
Download software ranking
终极变速大师Speeder3.26
传奇私服架设教程-chm
Boxer's Top ten classic battle7
Unix video tutorial7
jBuilder2006
C语言教程TXT
Desire a peach blossom
asp.net技术内幕
天龙八部十二宫服务端
Unix video tutorial17
delv published in(发表于) 2014/1/23 3:13:57 Edit(编辑)
利用DataGrid显示某目录下的所有文件_[Asp.Net教程]

利用DataGrid显示某目录下的所有文件_[Asp.Net教程]

利用DataGrid显示某目录下的所有文件_[Asp.Net教程]


























.NET Framework提供两个访问目录信息的类和两个访问文件信息的类,钥访问目录,可以使用Directory类,也可以使用DirectoryInfo类,对应于文件,也有File类和FileInfo类。这两个类之间的区别在于返回的信息和使用的方法不同。Directory和File类属于静态类,在使用时你不必创建实例,例如:要删除文件,可以File.Delete(filePath),要检测文件夹是否存在可以Directory.Exists(directoryPath)。而带Info的类在使用时必须先进行实例化,并在构造函数里指名文件名字或者目录名字,因此,删除文件可以用Dim myFile as File = New File(filePath),myFile.Delete()。




这两个类都提供了得到一个文件夹下的所有文件或者某种扩展名的文件的方法,即GetFiles()。




' --- Directory 例子 ----
Dim files() as String = Directory.GetFiles(directoryPath[, optionalWildCard])




' --- DirectoryInfo 例子 ----
Dim myDir as DirectoryInfo = New DirectoryInfo(directoryPath)
Dim fileInfos() as FileInfo = myDir.GetFiles([optionalWildCard])




值得注意的是,两者返回的类型是不同的,一个是String类型的数组,另外一个是FileInfo类型的数组。下面就是绑定的方法:




VB.NET




<%@ Import Namespace="System.IO" %>




AutoGenerateColumns="False" AlternatingItemStyle-BackColor="#eeeeee"
HeaderStyle-BackColor="Navy" HeaderStyle-ForeColor="White"
HeaderStyle-Font-Size="15pt" HeaderStyle-Font-Bold="True">

HeaderText="文件名" />
ItemStyle-HorizontalAlign="Center" DataFormatString="{0:d}" />
ItemStyle-HorizontalAlign="Right"
DataFormatString="{0:#,### 字节}" />




来源:孟宪会之精彩世界













































添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.