日期:2014-05-17 浏览次数:20458 次
SqlConnection con=new SqlConnection("server=.;database=study;uid=sa;pwd=sa"); con.Open(); string sql="select * from download where fileID='"+fileID+"'"; SqlCommand cmd=new SqlCommand(sql,con); SqlDataReader sdr=cmd.ExecuteReader(); sdr.Read(); Response.Buffer=true; Page.Response.Clear();//清除缓冲区所有内容 Page.Response.ContentType="application/octet-stream"; Page.Response.AddHeader("Content-Disposition","attachment;filename="+HttpUtility.UrlEncode(sdr["fileName"].ToString())); byte[] file=(Byte[])sdr["fileData"];//读出数据 int a=file.Length; Response.BinaryWrite(file); Response.Flush(); Response.End(); sdr.Close(); con.Close();