asp.net遍历文件夹下所有子文件夹并绑定到gridview上的方法
程序员文章站
2024-02-24 21:50:58
遍历文件夹下所有子文件夹,并且遍历配置文件某一节点中所有key,value并且绑定到gridview上
helper app_helper = new helpe...
遍历文件夹下所有子文件夹,并且遍历配置文件某一节点中所有key,value并且绑定到gridview上
helper app_helper = new helper(); dataset ds = new dataset(); datatable dt = new datatable(); protected void page_load(object sender, eventargs e) { gvwbind(); } #region 绑定gridview /// <summary> /// 绑定gridview /// </summary> protected void gvwbind() { ini.inipath iniinipath = new ini.inipath(); ini.inifile iniinifile = new ini.inifile(iniinipath.getinipath()); string foldernames = app_helper.getallfolder(server.mappath("../../appdir"));//获得appdir文件夹下所有子文件夹名 string[] foldername = new string[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 (int i = 0; i < foldername.length - 1; i++) { datarow row = 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
下一篇: SpringBoot持久化层操作支持技巧