2013-01-10 41 views
0

有沒有辦法在不使用Sql表的情況下在asp.net listview中列出子文件夾及其文件?在列表視圖中列出文件夾名稱和文件內容

感謝

+0

你想遞歸或僅列出它們文件夾內容的單一級別? –

+1

是的。儘管如此,您仍需要詢問具體的編程問題才能獲得幫助。 –

+0

將會有如下文件夾:1234,5832,123123.在這些文件夾中有文件fd3_xxx_stmt,fd3_xxx_war,fd3_xxx_tax。我的列表視圖有三列陳述,保證和稅收。如果文件夾1234有這些文件,那麼我的列表視圖應該在語句列下:1234 \ fd3_xxx_stmt,授權列:1234 \ fd3_xxx_war –

回答

1

假設你有一個列表視圖名爲ListView1 你可以做的東西像下面列出的文件名:

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! 
     } 
    } 
相關問題