程晓晖

博客园 首页 新随笔 联系 订阅 管理

protected void Page_Load(object sender, EventArgs e)
    {

        //string fileName = Request.QueryString["n"];//获取文件名
        int f_id = Int32.Parse(Request.QueryString["id"]);//获取文件的ID
        files fss = filesBLL.Select(f_id);
        string fileName = fss.f_filename;

        System.IO.FileStream fs = null;
        fs = System.IO.File.Open(Server.MapPath(@"../gxxz/upload/" + fileName), System.IO.FileMode.Open);
        byte[] btFile = new byte[fs.Length];
        fs.Read(btFile, 0, Convert.ToInt32(fs.Length));//将文件读到数组中
        fs.Close();
        string strFileName = "attachment;filename=" + HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8);
        this.Response.AddHeader("Content-disposition", strFileName);
        this.Response.ContentType = "application/octet-staream";
        this.Response.BinaryWrite(btFile);


        //修改此文件的的下载次数
      //  string where = "f_id=" + f_id;
       // IList<files> list = filesBLL.Select(where);
       // files f = list[0];
       // f.f_readdegree += 1;
      
       // filesBLL.Update(f);
        this.Response.End();
    }

posted on 2010-12-10 15:28  fumen  阅读(257)  评论(0编辑  收藏  举报