博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
GridView 实现LinkButton下载文件/附件
阅读量:6840 次
发布时间:2019-06-26

本文共 1133 字,大约阅读时间需要 3 分钟。

 

下载

 

protected void gdvwUpFile_RowCommand(object sender, GridViewCommandEventArgs e)    {        if (e.CommandName== "DownFile")        {            int id = int.Parse(e.CommandArgument.ToString());            DataBase db = new DataBase();            string sqlDown = "select  UFFileName from  PTestUploadFiles where UFID=" + id+"";            DataTable dt= db.GetDataSet(sqlDown).Tables[0];            string fileName = dt.Rows[0][0].ToString();            string filePath = Server.MapPath("/UpFile/"+fileName);                  FileStream fs = new FileStream(filePath, FileMode.Open);            byte[] bytes = new byte[(int)fs.Length];            fs.Read(bytes, 0, bytes.Length);            fs.Close();            Response.ContentType = "application/octet-stream";            Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));            Response.BinaryWrite(bytes);            Response.Flush();            Response.End();        }    }

 

转载于:https://www.cnblogs.com/vip-huliji/p/6213587.html

你可能感兴趣的文章