首页 > 代码库 > GridView 实现LinkButton下载文件/附件
GridView 实现LinkButton下载文件/附件
<asp:TemplateField > <ItemTemplate> <asp:LinkButton ID="lbtnDownFile" runat="server" CommandName="DownFile" CommandArgument=‘<%# Eval("UFID") %>‘ >下载</asp:LinkButton> </ItemTemplate> </asp:TemplateField>
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(); } }
GridView 实现LinkButton下载文件/附件
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。