各位高手帮忙,我的项目里边有个文件夹“test”,我的文件都上传到这个文件夹下了,我有什么办法可以获取到这个文件夹下的所有文件,并且让它们在页面显示出来(供我删除,或下载)【asp.net】
先谢了!

解决方案 »

  1.   

    Directory.GetFiles 方法http://msdn.microsoft.com/zh-cn/library/system.io.directory.getfiles.aspx
      

  2.   

    http://wenku.baidu.com/view/7716343f5727a5e9856a615f.html
      

  3.   

    string[] files = Directory.GetDirectories("D:\\", "*.*", SearchOption.AllDirectories);
      

  4.   

    protected void Page_Load(object sender, EventArgs e)
        {
            WebUI.isLogin();
            if (!IsPostBack)
            {
                BindDDLAccess();        //绑定文件名
            }
        }
        public void BindDDLAccess()
        {
            System.IO.DirectoryInfo info = new System.IO.DirectoryInfo(System.Web.HttpContext.Current.Server.MapPath("~/Copy/"));        System.IO.FileInfo[] aa = info.GetFiles();        for (int i = 0; i < aa.Length; i++)
            {
                Regex re = new Regex(@"\w*\.\w*");
                string st = re.Match(aa[i].FullName).Value.ToString();
                int num = i;
                this.ddlAccess.Items.Insert(i, new ListItem(st, i.ToString()));
            }
            this.ddlAccess.Items.Insert(0, "--请选择--");
        }    protected void btnAdd_Click(object sender, EventArgs e)
        {
            string backupPath = urlconvertorlocal("/Copy/") + this.ddlAccess.SelectedItem.Text.ToString();
            string sourcePath = urlconvertorlocal("/App_Data/HDZS.mdb");
            string message = Recover(backupPath, sourcePath);
            WebUI.Alert(message, this.Page);
        }    /// <summary> 
        /// 恢复Access数据库
        /// </summary> 
        /// <param name="backupPath">备份数据库绝对路径</param> 
        /// <param name="sourcePath">当前数据库绝对路径</param> 
        public string Recover(string backupPath, string sourcePath)
        {
            if (!File.Exists(backupPath))
            {
                return "备份数据库不存在!";
            }
            try
            {
                File.Copy(backupPath, sourcePath, true);
                return "恢复成功!";
            }
            catch (IOException ixp)
            {
                throw new Exception(ixp.ToString());
            }    }    /// <summary>
        /// 删除指定文件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnDel_Click(object sender, EventArgs e)
        {        System.IO.FileInfo file = new System.IO.FileInfo(urlconvertorlocal("/Copy/") + this.ddlAccess.SelectedItem.Text.ToString());
            if (!file.Exists)
            {
                WebUI.Alert("文件不存在!", this.Page);
            }
            else
            {
                file.Delete();
                WebUI.AlertAndRedirect("删除成功!", "Edit_Access.aspx", this.Page);
            }
        }
        /// <summary>
        /// 转换为绝对路径
        /// </summary>
        /// <param name="imagesurl1"></param>
        /// <returns></returns>
        private string urlconvertorlocal(string imagesurl1)
        {        string tmpRootDir = Server.MapPath(System.Web.HttpContext.Current.Request.ApplicationPath.ToString());//获取程序根目录        string imagesurl2 = tmpRootDir + imagesurl1.Replace(@"/", @"\"); //转换成绝对路径        return imagesurl2;    }http://blog.csdn.net/ws297636199/archive/2010/11/04/5987170.aspx
    比着葫芦画瓢。