代码如下:
View Code
1 protected void btnDelete(object sender, EventArgs e)
2 {
3
4 try
5 {
6 System.IO.DirectoryInfo path = new System.IO.DirectoryInfo(Server.MapPath("/Test"));
7 deletefile(path);
8 Page.RegisterStartupScript("Startup", "<script>alert('清理数据成功!');</script>");
9 }
10 catch
11 {
12 Page.RegisterStartupScript("Startup", "<script>alert('清理数据失败!');</script>");
13 }
14 }
15 private void deletefile(System.IO.DirectoryInfo path)
16 {
17 foreach (System.IO.DirectoryInfo d in path.GetDirectories())
18 {
19 deletefile(d);
20 }
21 foreach (System.IO.FileInfo f in path.GetFiles())
22 {
23 f.Delete();
24 }
25 }