asp.net 遍历文件夹下全部子文件夹并绑定到gridview上

遍历文件夹下所有子文件夹,并且遍历配置文件某一节点中所有key,value并且绑定到GridView上

C#代码  

    1. Helper app_Helper = new Helper();
    2. DataSet ds = new DataSet();
    3. DataTable dt = new DataTable();
    4. protected void Page_Load(object sender, EventArgs e)
    5. {
    6. gvwBind();
    7. }
    8. #region 绑定GridView
    9. /// <summary>
    10. /// 绑定GridView
    11. /// </summary>
    12. protected void gvwBind()
    13. {
    14. INI.INIPath iniINIPath = new INI.INIPath();
    15. INI.INIFile iniINIFile = new INI.INIFile(iniINIPath.getINIPath());
    16. string FolderNames = app_Helper.GetAllFolder(Server.MapPath("../../APPDIR"));//获得APPDIR文件夹下所有子文件夹名
    17. string[] FolderName = new string[FolderNames.Split(‘,‘).Length - 1];//声明个数组为了保存文件夹绝对路径
    18. FolderName = FolderNames.Split(‘,‘);//给文件夹绝对路径数组赋值
    19. dt.Columns.Add("LKNAME", typeof(string));
    20. dt.Columns.Add("qdjsjm", typeof(string));
    21. dt.Columns.Add("qdipdz", typeof(string));
    22. for (int i = 0; i < FolderName.Length - 1; i++)
    23. {
    24. DataRow row = dt.NewRow();
    25. FolderName[i] = FolderName[i].Substring(FolderName[i].LastIndexOf(‘\\‘) + 1);//截取文件夹名
    26. row["LKNAME"] = FolderName[i];//给 LKNAME 字符赋值
    27. if (!iniINIFile.IniReadValue("dzjclkzp", FolderName[i]).Equals(""))//配置文件中是否存在相同文件夹名的key
    28. {
    29. row["qdjsjm"] = iniINIFile.IniReadValue("dzjclkzp", FolderName[i]).Split(‘,‘)[0];//给qdjsjm字段赋值
    30. row["qdipdz"] = iniINIFile.IniReadValue("dzjclkzp", FolderName[i]).Split(‘,‘)[1];//给qdipdz字段赋值
    31. }
    32. dt.Rows.Add(row);
    33. }
    34. gvwGKWH.DataSource = dt;//绑定到数组
    35. gvwGKWH.DataBind();
    36. }
    37. #endregion 绑定GridView

推荐篇文章

asp.net 遍历文件夹下全部子文件夹并绑定到gridview上

时间: 2024-07-29 19:32:50

asp.net 遍历文件夹下全部子文件夹并绑定到gridview上的相关文章

Python扫描指定文件夹下(包含子文件夹)的文件

扫描指定文件夹下的文件.或者匹配指定后缀和前缀的函数. 假设要扫描指定文件夹下的文件,包含子文件夹,调用scan_files("/export/home/test/") 假设要扫描指定文件夹下的特定后缀的文件(比方jar包),包含子文件夹,调用scan_files("/export/home/test/", postfix=".jar") 假设要扫描指定文件夹下的特定前缀的文件(比方test_xxx.py).包含子文件夹,调用scan_files

取消文件夹下的子文件夹和文件的只读属性

private void UnsetReadOnly(string dirPath) {//http://bbs.csdn.net/topics/380233913 string[] dirPathes = Directory.GetDirectories(dirPath, "*.*", SearchOption.AllDirectories); string[] filePathes = Directory.GetFiles(dirPath, "*.*", Sea

FATFS-f_deldir-删除文件夹(删除子文件夹及文件连同其本身)

转载请注明出处:http://blog.csdn.net/u011833609/article/details/47803551 //==================================================================================================== //函 数 名 : f_deldir //函数功能 : 移除一个文件夹,包括其本身和其子文件夹,子文件 //输 入 : const TCHAR *path---指向

.Net 遍历目录下的子文件夹和文件

今天再完成一道任务的时候需要遍历得到所有txt文件,搜索很久终于得到了一个很方便的方法. foreach (string o in Directory.GetDirectories(@"D:\Logs") { foreach (string i in Directory.GetFiles(o)) { FileInfo fi = new FileInfo(i); if (fi.Extension.Equals(".txt")) { //这里我就可以操作我得到的满足条件

linux系统下修改文件夹权限及其子文件夹权限

root用户下 chmod -R 777 eclipse

Matlab学习:读取指定文件夹及其五级子文件夹内的文件

OpenCV2.4.X版本提供了三个函数来读取指定目录内的文件,它们分别是: (1)GetListFiles:读取指定目录内所有文件,不包含子目录: (2)GetListFilesR:读取指定目录及其子目录(仅一级子目录)内所有文件: (3)GetListFolders:读取指定目录内所有目录,不包含文件: 然而,Matlab中并没有对应的函数,有人可能会说dir不就可以吗,但dir返回的值还进行一些处理我们才能用的,如移除返值中包含的父目录及当前目录.这里我就写了一段代码来读取指定目录及其子目

MATLAB遍历子文件夹及其下文件

MATLAB遍历子文件夹及其下文件 以前从未遇到过用MATLAB批处理文件的情况,此次项目需要批量将二进制数据文件导入matlab进行svm分类,现将matlab遍历子文件夹及其文件的方法记录下来. 文件目录结构 /maindir |-- subdir1 |-- datafile1.dat |-- datafile2.dat |-- subdir2 |-- datafiel3.dat |-- datafiel4.dat |-- subdir3 |-- datafile5.dat |-- data

Java 遍历指定文件夹及子文件夹下的文件

/** * 遍历指定文件夹及子文件夹下的文件 * * @author testcs_dn * @date 2014年12月12日下午2:33:49 * @param file 要遍历的指定文件夹 * @param collector 符合条件的结果加入到此List<File>中 * @param pathInclude 路径中包括指定的字符串 * @param fileNameInclude 文件名称(不包括扩展名)中包括指定的字符串 * @param extnEquals 文件扩展名为指定字

遍历文件夹及其子文件夹下的.pdf文件,并解压文件夹下所有的压缩包

List<PDFPATH> pdfpath = new List<PDFPATH>(); List<string> ziplist = new List<string>(); public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { FolderBrowserDialog dialog = new FolderBrows