protected void Button1_Click( object sender, EventArgs e) { try { Label3.Visible = true; Label3.Text = ""; TableRow tr; TableCell tc; Random autoRand = new Random(); ArrayList arr = new ArrayList(); double percentage = Convert.ToInt32(TextBox3.Text); percentage = percentage / 100; string name = TextBox1.Text; string str = "D:\\XXX\\" + name + "\\"; int num = 0; DirectoryInfo dir = new DirectoryInfo(str); foreach (FileSystemInfo fsi in dir.GetFileSystemInfos()) { filename = ""; if (fsi is FileInfo) { num++; filename = fsi.FullName; arr.Add(filename); } if (fsi is DirectoryInfo) { num++; filename = fsi.FullName; arr.Add(filename); } } for (double i = 1; i <=percentage * num; i += 1) { int sum =Convert.ToInt32(percentage * num); foreach (FileSystemInfo fsi in dir.GetFileSystemInfos()) { filename = arr[autoRand.Next(1, num)].ToString(); tr = new TableRow(); tc = new TableCell(); tc.Controls.Add(new LiteralControl(filename.ToString())); tr.Cells.Add(tc); Table1.Rows.Add(tr); break; } } } catch { Label3.Text = "不存在该项目,请确定后重新搜索!"; } }