public void listFiles(string dir, int level)

{ try { //获取文件列表 string[] files = Directory.GetFiles(dir); String preStr = ""; for (int i = 0; i < level; i++) { preStr += "&nbsp;&nbsp;&nbsp;"; } foreach (string f in files) { if (f.LastIndexOf("\\") == -1) { Response.Write(preStr + f.Substring(f.LastIndexOf("/") + 1)+"<br />"); } else { Response.Write(preStr + f.Substring(f.LastIndexOf("\\") + 1) + "<br />"); } } //获取目录列表 string[] dirs = Directory.GetDirectories(dir); foreach (string d in dirs) { if (d.LastIndexOf("\\") == -1) { Response.Write(preStr + d.Substring(d.LastIndexOf("/") + 1) + "<br />"); } else { Response.Write(preStr + d.Substring(d.LastIndexOf("\\") + 1) + "<br />"); } if (Directory.Exists(d)) { listFiles(d, level + 1); } } } catch (Exception ex) { Response.Write(ex.Message); } }===========================================================调用:string testDir = @"E:\EveryDayWorks\2013-1\1-18";listFiles(testDir, 0);