Reputation: 367
Is there a way to list the subfolders and its files in a asp.net listview without using a Sql table?
Thanks
Upvotes: 0
Views: 886
Reputation: 2306
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!
}
}
Upvotes: 1