asp.net遍历文件夹下所有子文件夹并绑定到gridview上的方法
遍历文件夹下所有子文件夹,并且遍历配置文件某一节点中所有key,value并且绑定到GridView上
Helperapp_Helper=newHelper();
DataSetds=newDataSet();
DataTabledt=newDataTable();
protectedvoidPage_Load(objectsender,EventArgse)
{
gvwBind();
}
#region绑定GridView
///<summary>
///绑定GridView
///</summary>
protectedvoidgvwBind()
{
INI.INIPathiniINIPath=newINI.INIPath();
INI.INIFileiniINIFile=newINI.INIFile(iniINIPath.getINIPath());
stringFolderNames=app_Helper.GetAllFolder(Server.MapPath("../../APPDIR"));//获得APPDIR文件夹下所有子文件夹名
string[]FolderName=newstring[FolderNames.Split(',').Length-1];//声明个数组为了保存文件夹绝对路径
FolderName=FolderNames.Split(',');//给文件夹绝对路径数组赋值
dt.Columns.Add("LKNAME",typeof(string));
dt.Columns.Add("qdjsjm",typeof(string));
dt.Columns.Add("qdipdz",typeof(string));
for(inti=0;i<FolderName.Length-1;i++)
{
DataRowrow=dt.NewRow();
FolderName[i]=FolderName[i].Substring(FolderName[i].LastIndexOf('\\')+1);//截取文件夹名
row["LKNAME"]=FolderName[i];//给LKNAME字符赋值
if(!iniINIFile.IniReadValue("dzjclkzp",FolderName[i]).Equals(""))//配置文件中是否存在相同文件夹名的key
{
row["qdjsjm"]=iniINIFile.IniReadValue("dzjclkzp",FolderName[i]).Split(',')[0];//给qdjsjm字段赋值
row["qdipdz"]=iniINIFile.IniReadValue("dzjclkzp",FolderName[i]).Split(',')[1];//给qdipdz字段赋值
}
dt.Rows.Add(row);
}
gvwGKWH.DataSource=dt;//绑定到数组
gvwGKWH.DataBind();
}
#endregion绑定GridView