遍历文件夹里面的文件,并绑定到dropdownlist

string rep_path = Server.MapPath("reports");
        string[] files = Directory.GetFiles(rep_path);
        string[] report_files = new string[files.Length];
        for (int i = 0; i < files.Length; i++)
        {
           
            report_files[i] = files[i].Replace(rep_path + "//", "");
        }
        DropDownList1.DataSource = report_files;

        DropDownList1.DataBind();

原文地址:https://www.cnblogs.com/tongdengquan/p/6090606.html