<asp:LinkButton ID="upload" runat="server" Text="下载" OnClick="upload_Click" />
int rowIndex = 0;
LinkButton btn = (LinkButton)sender;
GridViewRow gvr = (GridViewRow)btn.Parent.Parent;
rowIndex = gvr.RowIndex;
string mID = GridView1.Rows[rowIndex].Cells[0].Text.Trim();
string sqlStr = "select * from SFPrintPaper where ID='" mID "' ";
dt = Utils.executeQueryT(sqlStr, connStr);
if (dt.Rows.Count > 0)
{
String FullFileName = System.Web.HttpContext.Current.Server.MapPath("../../BarTender/" dt.Rows[0]["FileName"].ToString().Trim() ".btw");
FileInfo DownloadFile = new FileInfo(FullFileName);
Response.Clear();
Response.ClearContent();
Response.ClearHeaders();
Response.HeaderEncoding = Encoding.Default;
Response.AddHeader("Content-Disposition", " attachment;filename=" System.Web.HttpUtility.UrlEncode("Label.btw", System.Text.Encoding.UTF8).Replace(" ", ""));
Response.ContentType = "application/octet-stream";
Response.ContentEncoding = Encoding.Default;
Response.WriteFile(DownloadFile.FullName);
Response.Flush();
Response.OutputStream.Close();
Response.End();
}
<a href='filePath' target='_blank'>下载</a>
可以使用javascript控制,如果想简单使用一个js库,如jquery
简单的做法是 <a> 标签添加文件路径
复杂点的话,如果你想加权限控制,如下:
Response.ContentType = "application/x-zip-compressed";
Response.AddHeader("Content-Disposition", "attachment;filename=" fileurl "");
// Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
string filename = Server.MapPath("UpFile/" model.fileurl);
Response.TransmitFile(filename);