求一个能获得当前文件夹内所有文件的名称,大小,类型,属性,日期的函数。 RT 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 Directory.GetCurrentDirectory 获取应用程序的当前工作目录Directory.GetFiles 返回指定目录中的文件的名称File.GetAttributes 获取在此路径上的文件的 FileAttributes有很多这样的东西,在System.IO命名空间 还有 FileInfoMSDN:ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.2052/cpref/html/frlrfSystemIOFileInfoMembersTopic.htm 刚写的一个,看看和不合你的意思<%@ Page Language="C#" ContentType="text/html" ResponseEncoding="gb2312" %><%@ Import Namespace="System.IO"%><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title></title></head><script language="c#" runat="server"> public void Page_Load(Object src,EventArgs e) { string strCurrentDir; //初始化一些数据 if(!Page.IsPostBack) { strCurrentDir=Server.MapPath("."); lblCurrentDir.Text=strCurrentDir; tbCurrentDir.Text=strCurrentDir; } else { strCurrentDir=tbCurrentDir.Text; tbCurrentDir.Text=strCurrentDir; lblCurrentDir.Text=strCurrentDir; } FileInfo fi; DirectoryInfo di; TableCell td; TableRow tr; //设定Table中的数据,先搞定第一行 tr=new TableRow(); td=new TableCell(); td.Controls.Add(new LiteralControl("文件名")); tr.Cells.Add(td); td=new TableCell(); td.Controls.Add(new LiteralControl("文件大小")); tr.Cells.Add(td); td=new TableCell(); td.Controls.Add(new LiteralControl("更新时间")); tr.Cells.Add(td); tbDirInfo.Rows.Add(tr); string FileName; //文件名称 string FileExt; //文件扩展名 string FilePic; //图像文件类型 long FileSize; //文件大小 DateTime FileModify; //最后更新时间 DirectoryInfo dir=new DirectoryInfo(strCurrentDir); foreach(FileSystemInfo fsi in dir.GetFileSystemInfos()) { FilePic=""; FileName=""; FileSize=0; FileExt=""; if(fsi is FileInfo) { //表示当前fsi是文件 fi=(FileInfo)fsi; FileName=fi.Name; FileExt=fi.Extension; FileSize=fi.Length; FileModify=fi.LastWriteTime; //通过扩展名来确定显示图片的类型 switch(FileExt) { case ".jpg": FilePic="jpg图像"; break; case ".gif": FilePic="gif图像"; break; case ".tiff": FilePic="tiff图像"; break; case ".bmp": FilePic="bmp图像"; break; default: FilePic="文件"; break; } } else { //当前为目录 di=(DirectoryInfo)fsi; FileName=di.Name; FileModify=di.LastWriteTime; FilePic="目录"; } //组建新的行 tr=new TableRow(); td=new TableCell(); td.Controls.Add(new LiteralControl(FilePic+" "+FileName)); tr.Cells.Add(td); td=new TableCell(); td.Controls.Add(new LiteralControl(FileSize.ToString())); tr.Cells.Add(td); td=new TableCell(); td.Controls.Add(new LiteralControl(FileModify.ToString())); tr.Cells.Add(td); tbDirInfo.Rows.Add(tr); } }</script><body><form runat="server">请选择浏览目录:<asp:TextBox ID="tbCurrentDir" runat="server" /><br>当前目录为:<asp:label ID="lblCurrentDir" runat="server" /><br><asp:table ID="tbDirInfo" Font-Size="9pt" runat="server" /><br></form></body></html> 在File类里有很多FileInfo也可以 很多也,遇事先问google,再问csdn,这种问题就不用问了 File FileInfo就可以搞顶了......... 如何在data binding时实现动态效果 用HttpModule做文件上传用到ReadEntityBody函数后就总是出现等待60秒 IE漏洞??? 大家好小弟现在问个小问题哦我想在服务器端执行一个外部的程序怎么写啊? 寻求高手合作 求问用什么控件好 为什么会这样? 如何定位到添加的节点上? session赋值和取值问题 常用问题请教:采用什么样的数据类绑定到组合框以及查询最高效?谢谢!!! ASP登录提交问题 自动的插入字段
Directory.GetFiles 返回指定目录中的文件的名称
File.GetAttributes 获取在此路径上的文件的 FileAttributes有很多这样的东西,在System.IO命名空间
ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.2052/cpref/html/frlrfSystemIOFileInfoMembersTopic.htm
<%@ Page Language="C#" ContentType="text/html" ResponseEncoding="gb2312" %>
<%@ Import Namespace="System.IO"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title></title>
</head>
<script language="c#" runat="server">
public void Page_Load(Object src,EventArgs e)
{
string strCurrentDir;
//初始化一些数据
if(!Page.IsPostBack)
{
strCurrentDir=Server.MapPath(".");
lblCurrentDir.Text=strCurrentDir;
tbCurrentDir.Text=strCurrentDir;
}
else
{
strCurrentDir=tbCurrentDir.Text;
tbCurrentDir.Text=strCurrentDir;
lblCurrentDir.Text=strCurrentDir;
}
FileInfo fi;
DirectoryInfo di;
TableCell td;
TableRow tr;
//设定Table中的数据,先搞定第一行
tr=new TableRow();
td=new TableCell();
td.Controls.Add(new LiteralControl("文件名"));
tr.Cells.Add(td);
td=new TableCell();
td.Controls.Add(new LiteralControl("文件大小"));
tr.Cells.Add(td);
td=new TableCell();
td.Controls.Add(new LiteralControl("更新时间"));
tr.Cells.Add(td);
tbDirInfo.Rows.Add(tr);
string FileName; //文件名称
string FileExt; //文件扩展名
string FilePic; //图像文件类型
long FileSize; //文件大小
DateTime FileModify; //最后更新时间
DirectoryInfo dir=new DirectoryInfo(strCurrentDir);
foreach(FileSystemInfo fsi in dir.GetFileSystemInfos())
{
FilePic="";
FileName="";
FileSize=0;
FileExt="";
if(fsi is FileInfo)
{
//表示当前fsi是文件
fi=(FileInfo)fsi;
FileName=fi.Name;
FileExt=fi.Extension;
FileSize=fi.Length;
FileModify=fi.LastWriteTime;
//通过扩展名来确定显示图片的类型
switch(FileExt)
{
case ".jpg":
FilePic="jpg图像";
break;
case ".gif":
FilePic="gif图像";
break;
case ".tiff":
FilePic="tiff图像";
break;
case ".bmp":
FilePic="bmp图像";
break;
default:
FilePic="文件";
break;
}
}
else
{
//当前为目录
di=(DirectoryInfo)fsi;
FileName=di.Name;
FileModify=di.LastWriteTime;
FilePic="目录";
}
//组建新的行
tr=new TableRow();
td=new TableCell();
td.Controls.Add(new LiteralControl(FilePic+" "+FileName));
tr.Cells.Add(td);
td=new TableCell();
td.Controls.Add(new LiteralControl(FileSize.ToString()));
tr.Cells.Add(td);
td=new TableCell();
td.Controls.Add(new LiteralControl(FileModify.ToString()));
tr.Cells.Add(td);
tbDirInfo.Rows.Add(tr);
}
}
</script>
<body>
<form runat="server">
请选择浏览目录:<asp:TextBox ID="tbCurrentDir" runat="server" /><br>
当前目录为:<asp:label ID="lblCurrentDir" runat="server" /><br>
<asp:table ID="tbDirInfo" Font-Size="9pt" runat="server" /><br>
</form>
</body>
</html>
FileInfo也可以
FileInfo
就可以搞顶了.........