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

📄 filelist.aspx

📁 亲密接触ASP.Net
💻 ASPX
字号:
<% @ Page Language="C#" %>
<% @ Import Namespace="System.IO" %>
<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("<img src='name.gif'>"));
	tr.Cells.Add(td);

	td = new TableCell();
	td.Controls.Add(new LiteralControl("<img src='size.gif'>"));
	tr.Cells.Add(td);

	td = new TableCell();
	td.Controls.Add(new LiteralControl("<img src='lastmodify.gif'>"));
	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 = "";
		FileExt = "";
		FileSize = 0;

		if(fsi is FileInfo)
		{
			//表示当前fsi是文件
			fi = (FileInfo)fsi;
			FileName	= fi.Name;
			FileExt		= fi.Extension;
			FileSize	= fi.Length;
			FileModify	= fi.LastWriteTime; 
			//通过扩展名来选择文件显示图标
			switch(FileExt)
			{
				case ".gif":
					FilePic = "gif.gif";
					break;
				default:
					FilePic = "other.gif";
					break;
			}
			FilePic = "<img src='"+FilePic+"' width=25 height=20>";
		}
		else
		{
			//当前为目录
			di = (DirectoryInfo)fsi;
			FileName	= di.Name;
			FileModify	= di.LastWriteTime;
			FilePic = "<img src='directory.gif' width=25 height=20>";
		}

		//组建新的行
		tr = new TableRow();

		td = new TableCell();
		td.Controls.Add(new LiteralControl(FilePic+"&nbsp;"+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>
<html>
<head>
<title></title>
</head>
<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" />
</form>
</body>
</html>

⌨️ 快捷键说明

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