- protected void Page_Load(object sender, EventArgs e)
- {
- if(!IsPostBack){
- string paths = @"F:/学习专用文件夹/网页";
- Boolean flag = ReadFiles(paths);
- if (flag)
- {
- Txtmess.Text = Directory.GetFiles(paths).ToString();
- }
- else
- {
- Response.Write("对不起,有误");
- }
- }
- }
- private Boolean ReadFiles(string dirroot)
- {
- Boolean flag = false;
- string[] rootdirs = Directory.GetDirectories(dirroot);//当前目录的子目录
- string[] rootFiles = Directory.GetFiles(dirroot);//目录下的文件
- try
- {
- foreach (string s2 in rootFiles)
- {
- Response.Write(s2+"<br/>");
- }
- foreach (string s1 in rootdirs)
- {
- ReadFiles(s1);
- }
- flag = true;
- }
- catch (Exception ex)
- {
- throw new Exception(ex.Message);
- }
- return flag;
- }