下载
//下载
protected void lbtnDown_Command(object sender, CommandEventArgs e)
{
string id = e.CommandArgument.ToString();
HR_Contract getupdown = new HR_Contract();
DataSet ds = getupdown.GetContractUpLinkByUpId(id);
string fileName = ds.Tables[0].Rows[0]["Contract_UpdateLink_Name"].ToString();//文件名
string filePath = Server.MapPath(ds.Tables[0].Rows[0]["Contract_UpdateLink_Addr"].ToString());//文件路径
//以字符流的形式下载文件
try
{
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();
}
catch
{
Page.RegisterStartupScript("", "<script language='javascript'>alert('该文件不存在!')</script>");
}
}