protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            DataTable dt = new DataTable();
            dt.Columns.Add(new DataColumn("Name", typeof(string)));
            string serverPath = Server.MapPath("File");//根目录下得file文件夹
            DirectoryInfo dir = new DirectoryInfo(serverPath);
            foreach (FileInfo fileName in dir.GetFiles())
            {
                DataRow dr = dt.NewRow();
                dr[0] = fileName;
                dt.Rows.Add(dr);
            }
            ListBox1.DataSource = dt;
            ListBox1.DataTextField = "Name";
            ListBox1.DataValueField = "Name";
            ListBox1.DataBind();
        }
    }
    protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
    {
        Session["txt"] = ListBox1.SelectedValue.ToString();
    }
    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        if (Session["txt"] != "")
        {
            //string FileName=Server.MapPath("../load/jtcy_ryxx.txt");
            string path = Server.MapPath("File/") + Session["txt"].ToString();
            FileInfo fi = new FileInfo(path);//用于获得文件信息
             
            if (fi.Exists)
            {
                //Response.AddHeader("Content-Disposition", "attachment;filename=" +Server.HtmlDecode( fi.Name));
                Response.Clear();//清空输出
                Response.Charset = "GB2312";//设定编码
                Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");
                // 添加头信息,为"文件下载/另存为"对话框指定默认文件名 
                Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(path));
                // 添加头信息,指定文件大小,让浏览器能够显示下载进度 
                Response.AddHeader("Content-Length", fi.Length.ToString());                // 指定返回的是一个不能被客户端读取的流,必须被下载 
                Response.ContentType = "application/ms-txt";
                Response.Flush();                // 把文件流发送到客户端 
                Response.WriteFile(fi.FullName );                Response.End();
                
            }
        }
    }asp.net文件下载