public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        showziyuanbao();
    }    public void showziyuanbao()
    {
        
        string sql = "select ziyuanbao from ziyuanku";
        SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["getcon"].ConnectionString);
        conn.Open();
        SqlCommand cmd = new SqlCommand(sql, conn);
        SqlDataReader dr = cmd.ExecuteReader();
        while (dr.Read())
        {
            ListBox3.Items.Add(dr["ziyuanbao"].ToString());
        }
        dr.Close();
        conn.Close();
    }    protected void LinkButton1_Click(object sender, EventArgs e)
    {    }
    protected void LinkButton2_Click(object sender, EventArgs e)
    {        string filePath = Server.MapPath("File") + "\\" + Session["txt"].ToString();
        if (Session["txt"] != null)
        {
            if (System.IO.File.Exists(filePath))
            {
                FileInfo file = new FileInfo(filePath);
                Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");                  Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(file.Name));   
                Response.AddHeader("Content-length", file.Length.ToString());
                Response.ContentType = "appliction/octet-stream";
                Response.WriteFile(file.FullName);
                Response.End();
            }
        }
    }
    protected void ListBox3_SelectedIndexChanged(object sender, EventArgs e)
    {
        Session["txt"] = ListBox3.SelectedItem.Text.ToString();
    }
}

解决方案 »

  1.   

    Response下载资源,要什么解释
      

  2.   

      string sql = "select ziyuanbao from ziyuanku";
      SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["getcon"].ConnectionString);
      conn.Open();
      SqlCommand cmd = new SqlCommand(sql, conn);
      SqlDataReader dr = cmd.ExecuteReader();
      while (dr.Read())
      {
      ListBox3.Items.Add(dr["ziyuanbao"].ToString());
      }
      dr.Close();
      conn.Close();
    数据库操作,查询资源FileInfo file = new FileInfo(filePath);
      Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8"); Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(file.Name));  
      Response.AddHeader("Content-length", file.Length.ToString());
      Response.ContentType = "appliction/octet-stream";
      Response.WriteFile(file.FullName);
      Response.End();Response下载资源,要什么解释
      

  3.   

    文件名存在数据库里面。文件存在磁盘上。读取文件,写入流,传给客户端。lz有 HTTP 协议的基础么?