在列表视图列表文件夹名和文件内容 [英] List folderName and file contents in listview

查看:88
本文介绍了在列表视图列表文件夹名和文件内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法列出在asp.net列表视图子文件夹和文件,而无需使用SQL表?

Is there a way to list the subfolders and its files in a asp.net listview without using a Sql table?

感谢

推荐答案

假设你有一个列表视图名为 ListView1的
你可以像下面列出的文件名做到这一点:

Assume that you have a listview named ListView1 You can do it with something like the following to list filenames.:

static void ListFiles(string sDir)
   {
       try
       {
           foreach (string d in Directory.GetDirectories(sDir))
           {
               foreach (string f in Directory.GetFiles(d))
               {
                    string fileName = Path.GetFileNameWithoutExtension(f);
                    ListViewItem item = new ListViewItem(fileName);
                    item.Tag =  f; //could get folder name: DirectoryInfo(d).Name


                    ListView1.Items.Add(item);
               }
               ListFiles(d);
           }
       }
       catch (System.Exception ex)
       {
           // handle exceptions here!
       }
   }

这篇关于在列表视图列表文件夹名和文件内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆