protected void Page_Load(object sender, EventArgs e)
{
string path = Server.MapPath("~");
DirectoryInfo dirInfo = new DirectoryInfo(path);
// 获取当前文件夹中含有'd'这个字母的文件或者文件夹
FileSystemInfo[] fileSystemList = dirInfo.GetFileSystemInfos("*d*");
DataTable dt = new DataTable();
dt.Columns.Add("文件名",typeof(string));
dt.Columns.Add("创建时间", typeof(DateTime));
dt.Columns.Add("是否只读", typeof(bool));
dt.Columns.Add("文件全名", typeof(string));
dt.Columns.Add("是否是根目录", typeof(string));
foreach (FileSystemInfo fis in fileSystemList)
{
DataRow row = dt.NewRow();
row["文件名"] = fis.Name;
row["创建时间"] = fis.CreationTime;
row["是否只读"] = (fis.Attributes & FileAttributes.ReadOnly) == 0 ? false : true;
row["文件全名"] = fis.FullName;
row["是否是根目录"] = (fis.Attributes & FileAttributes.Directory) == 0 ? false :
true;
dt.Rows.Add(row);
}
this.GridView1.DataSource = dt;
this.GridView1.DataBind();
}